我正处于使用python学习django的早期阶段。我以前两样都没做过
我正在学习一门课程,其中讲师演示了如何使用vagrant启动一个新项目,主目录中的一个文件名为Vagrantfile
,没有文件扩展名(讲师也一样)
以下是文件的内容:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/bionic64"
config.vm.box_version = "~> 20200304.0.0"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.provision "shell", inline: <<-SHELL
systemctl disable apt-daily.service
systemctl disable apt-daily.timer
sudo apt-get update
sudo apt-get install -y python3-venv zip
touch /home/vagrant/.bash_aliases
if ! grep -q PYTHON_ALIAS_ADDED /home/vagrant/.bash_aliases; then
echo "# PYTHON_ALIAS_ADDED" >> /home/vagrant/.bash_aliases
echo "alias python='python3'" >> /home/vagrant/.bash_aliases
fi
SHELL
end
根据我的理解,这一行echo "alias python='python3'" >> /home/vagrant/.bash_aliases
告诉vagrant,当我使用python
命令时,它应该将其视为我编写了python3
当我通过python -m venv ~/env
编写以下命令时,我得到以下消息作为响应:
Command 'python' not found, but can be installed with:
apt install python3
apt install python
apt install python-minimal
Ask your administrator to install one of them.
我在运行vagrant ssh
命令并且已经在虚拟机中之后调用该命令,并导航到vagrant dir。我知道它是因为在git bash中,它显示为我的当前位置vagrant@ubuntu-bionic:/vagrant$
我不确定它是否相关,或者它是否是一个不同的问题,但我要补充的是,即使我运行这个命令python3 -m venv ~/env
,我也会得到以下响应:
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/vagrant/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
如果我运行它推荐的install命令(使用sudo
),我会得到以下响应:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python3-venv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
这阻碍了我的学习,不知道如何与他一起前进。感谢您的帮助
我正试图在Ubuntu 20.04上重现这一点
此时,我的文件不包含别名。见https://github.com/michaelhochleitner/vagrant-test/blob/master/Vagrantfile
在无别名的浮动ssh中测试python
使用别名在vagrant ssh中测试python。 此时,我的文件包含了您帖子中的别名。见https://github.com/michaelhochleitner/vagrant-test/blob/master/Vagrantfile_with_alias
我假设
错误不是由文件中的别名引起的
尝试通过安装python3 venv来解决此问题。
在vagrant ssh之外的终端中
python
的输出是什么?在vagrant ssh之外的终端中
python3
的输出是什么?您使用的是哪种操作系统? 另见https://askubuntu.com/questions/958303/unable-to-create-virtual-environment-with-python-3-6
问题可能是将
python3
别名为python
,默认情况下,Ubuntu 18同时提供了Python 2(Python)和Python 3(Python 3),如果不小心更改,可能会导致不稳定,从细微的错误到系统无法启动,您可以:python3
python-is-python3
(尽管我不确定这是否在18中可用)无论如何,通过删除别名,一切都应该恢复正常
相关问题 更多 >
编程相关推荐