0

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.

3
  • have you installed Django to your virtualenv? Commented Feb 28, 2017 at 21:33
  • What is py -2 and py -3? It looks like you are expecting it to change the version of python within your env, but I have not heard of such a thing being possible. Commented Feb 28, 2017 at 21:36
  • Yes, Django was installed inside the virtualenv. Py -2 and Py -3 are what I was told are the preferred way to start python 2.X and 3.X on the same machine. The commands are provided by python when it is installed. Commented Feb 28, 2017 at 21:38

3 Answers 3

1

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 
Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

hey, when I try this it says "the path does not exist". I checked my path variable and it seems like my python3.6 folder is included in it but for some reason the executable is called "python" and not like "python36". Can I just rename it?
No, don't rename it. Just use the absolute path to that executable (i.e. include the folder names).
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.