[英]Ubuntu 14.04 - Python 3.4 - pyenv: command Not Found
I am trying to create a virtual environment for Python 3.4 on a fresh install of Ubuntu Server 14.04.我正在尝试在全新安装的 Ubuntu Server 14.04 上为 Python 3.4 创建一个虚拟环境。 I following the instructions for the venv module at:我按照以下 venv 模块的说明进行操作:
https://docs.python.org/3/library/venv.html#module-venv https://docs.python.org/3/library/venv.html#module-venv
I don't have a lot of Python 3.4 or Ubuntu experience.我没有很多 Python 3.4 或 Ubuntu 经验。
When I type the command:当我输入命令时:
pyvenv testDir
I get back:我回来了:
pyvenv: command not found
What is causing this?这是什么原因造成的?
Ubuntu 14.04 uses Python 2 by default, and the pyenv
command does not exist in Python 2 out of the box. Ubuntu 14.04 默认使用 Python 2,并且pyenv
命令在 Python 2 中不存在。
You can, however, use virtualenv
for the same purpose.但是,您可以将virtualenv
用于相同目的。 You just need to install it!你只需要安装它!
You should:你应该:
apt-get install -y python3 python-virtualenv
安装 Python 3 和 virtualenv apt-get install -y python3 python-virtualenv
virtualenv -p $(which python3) testDir
创建一个 Python 3 virtualenv: virtualenv -p $(which python3) testDir
source testDir/bin/activate
使用source testDir/bin/activate
虚拟环境It's also possible to create virtualenv by python itself.也可以通过 python 本身创建 virtualenv。 python3 -m venv myenv python3 -m venv myenv
see documentation https://docs.python.org/3/library/venv.html请参阅文档https://docs.python.org/3/library/venv.html
It's in the package python3.4-venv
(Linux Mint) or python3-venv
(Ubuntu - I guess).它在python3.4-venv
(Linux Mint) 或python3-venv
(Ubuntu - 我猜) 包中。
The advantages of venv
over virtualenv
are that (1) it's in vanilla Python3, (2) interpreter does retain tab-completion. venv
对于virtualenv
的优点是:(1)它在 vanilla Python3 中,(2)解释器确实保留了制表符补全。
Edit the .bashrc file present in your home directory by adding below code and save the file:通过添加以下代码来编辑主目录中的 .bashrc 文件并保存文件:
# Load pyenv automatically by adding
# the following to ~/.bashrc:
export PATH="/home/'Enter systemname here'/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
After this you can now run the following command:在此之后,您现在可以运行以下命令:
exec $SHELL
Now pyenv works properly现在 pyenv 正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.