Reputation: 618
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.
Upvotes: 0
Views: 904
Reputation: 114300
The key is that pip
installs things for a specific version of Python, and to a very specific location. Basically, the pip
command in your virtual environment is set up specifically for the interpreter that your virtual environment is using. So even if you explicitly call another interpreter with that environment activated, it will not pick up the packages pip
installed for the default interpreter.
Upvotes: 0
Reputation: 31895
Create virtual environment based on python3.6
virtualenv -p python3.6 env36
Activate it:
source env36/bin/activate
Then the venv36 has been activated, venv36
's pip is available now , you can install Django
as usual, and the package would be stored under env36/lib/python3.6/site-packages
:
pip install django
Upvotes: 1
Reputation: 362687
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.
Upvotes: 0