I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtuale
On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10
export PATH=/Users/{USERNAME}/.pyenv/versions/2.7.10/bin:$PATH
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python {virtual_env_name}
I also froze my requirements first so i could simply reinstall in the new virtualenv with:
pip install -r requirements.txt
Create environment for python3:
virtualenv --python=/usr/bin/python3 env
Activate it:
source env/bin/activate
Yes you just need to install the other version of python, and define the location of your other version of python in your command like :
virtualenv /home/payroll/Documents/env -p /usr/bin/python3
Since Python 3, the Python Docs suggest creating the virtual environment with the following command:
python3 -m venv <myenvname>
Please note that venv
does not permit creating virtual environments with other versions of Python. For that, install and use the virtualenv
package.
The pyvenv
script can be used to create a virtual environment
pyvenv /path/to/new/virtual/environment
but it has been deprecated since Python 3.6.
This was a bug with virtualenv. Just upgrading your pip should be the fix.
pip install --upgrade virtualenv
As already mentioned in multiple answers, using virtualenv is a clean solution. However a small pitfall that everyone should be aware of is that if an alias for python is set in bash_aliases like:
python=python3.6
this alias will also be used inside the virtual environment. So in this scenario running python -V
inside the virtual env will always output 3.6
regardless of what interpreter is used to create the environment:
virtualenv venv --python=pythonX.X