问题
I am trying to create a virtual environment for Python 3.4 on a fresh install of Ubuntu Server 14.04. I following the instructions for the venv module at:
https://docs.python.org/3/library/venv.html#module-venv
I don't have a lot of Python 3.4 or Ubuntu experience.
When I type the command:
pyvenv testDir
I get back:
pyvenv: command not found
What is causing this?
回答1:
Ubuntu 14.04 uses Python 2 by default, and the pyenv
command does not exist in Python 2 out of the box.
You can, however, use virtualenv
for the same purpose. You just need to install it!
You should:
- Install Python 3 and virtualenv
apt-get install -y python3 python-virtualenv
- Create a Python 3 virtualenv:
virtualenv -p $(which python3) testDir
- Activate the virtual environment with
source testDir/bin/activate
回答2:
It's also possible to create virtualenv by python itself. python3 -m venv myenv
see documentation https://docs.python.org/3/library/venv.html
回答3:
It's in the package python3.4-venv
(Linux Mint) or python3-venv
(Ubuntu - I guess).
The advantages of venv
over virtualenv
are that (1) it's in vanilla Python3, (2) interpreter does retain tab-completion.
回答4:
Edit the .bashrc file present in your home directory by adding below code and save the file:
# 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
来源:https://stackoverflow.com/questions/29954984/ubuntu-14-04-python-3-4-pyenv-command-not-found