AJwr AJwr -4 years ago 221
Python Question

Virtualenv installing modules with multiple Python versions

I am trying to start a Python 3.6 project by creating a virtualenv to keep the dependencies. I currently have both Python 2.7 and 3.6 installed on my machine, as I have been coding in 2.7 up until now and I wish to try out 3.6. I am running into a problem with the different versions of Python not detecting modules I am installing inside the virtualenv.

For example, I create a virtualenv with the command:

virtualenv venv


I then activate the virtualenv and install Django with the command:
pip install django


My problems arise when I activate either Python 2.7 or 3.6 with the commands
py -2
or
py -3
, neither of the interactive shells detect Django as being installed.

Django is only detected when I run the
python
command, which defaults to 2.7 when I want to use 3.6. Does anyone know a possible fix for this so I can get my virtualenv working correctly? Thanks! If it matters at all I am on a machine running Windows 7.

Answer Source

You have to select the interpreter when you create the virtualenv.

virtualenv --python=PYTHON36_EXE my_venv

Substitute the path to your Python 3.6 installation in place of PYTHON36_EXE. Then after you've activated, python executable will be bound to 3.6 and you can just pip install Django as usual.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download