Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a virtual environment for python 2.7.x?

I have 3 versions of python installed on my mac-OSX. Python 2.7.6 came pre-installed with the machine. I installed python 3.4.3 before. Now I installed python 2.7.11 by downloading the pkg file from the website. I also installed pip and virtualenv.

$python

If I run the above command on my terminal, the following is returned:

Python 2.7.11(...)...
.........
>>>

indicating that the latest version of python is working.

However, I created a virtual environment using virtualenv using the following command:

$virtualenv -p /usr/bin/python2.7 venv

and activated it using:

$source venv/bin/activate

If I now run the python command in the terminal with the virtual environment activated, the following is returned:

Python 2.7.6(...)...
.........
>>>

What is the problem here? Why isn't the virtual environment using python 2.7.11 and how can I fix this? Thanks.

Edit 1: If I run this command:

$python2.7

the following is returned:

python2.7.11(...)...
....
>>>

Edit 2: Running this command:

python -c "import os;print os.environ.get('VIRTUALENV_INTERPRETER_RUNNING')"

returns None.

Edit 3: I tried specifying which python interpreter to use for venv creation. My python 2.7.11 is located in a directory called python 2.7 in applications. I ran the following command:

$virtualenv -p /Applications/Python\ 2.7 myvenv 

The following error was returned:

OSError: [Errno13] Permission denied. 
like image 264
darkhorse Avatar asked Jan 07 '16 07:01

darkhorse


1 Answers

$virtualenv -p /usr/bin/python2.7 venv will use the Python interpreter in /usr/bin/python2.7.

If you want a different Python version in your environment then you have to specify the right path.

like image 68
narko Avatar answered Oct 07 '22 19:10

narko