4

I am trying to update the python version in my already existing virtual environment. I installed python using following steps

wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar xfz Python-2.7.11.tgz
cd Python-2.7.11/
./configure --prefix /usr/local/lib/python2.7.11 --enable-ipv6
make
sudo make install

I checked the version as well and its coming correctly

/usr/local/lib/python2.7.11/bin/python -V
Python 2.7.11

I have an existing virtualenv named test and I want to use python2.7.11 in this environment. It tried using

workon test --python /usr/local/lib/python2.7.11/bin/python

But the version of python is shown as the old one only

python -V
Python 2.7.6

If I create a new environment, it works fine

mkvirtualenv test2 -p /usr/local/lib/python2.7.11/bin/python
python -V
Python 2.7.11

I tried finding the solution but couldn't figure out how to modify python version in the existing virtual environment. Any help in figuring out the solution will be appreciated.

Thanks

Anurag
  • 1,521
  • 2
  • 17
  • 34

1 Answers1

2

The python interpreter in a virtualenv is definitive. But virtual envs are disposable, so I suggest you to create a new one with the good python interpreter.

loutre
  • 874
  • 8
  • 16
  • I have installed lot of stuff in this virtualenv and my website is running in this virtual env only. I don't want to setup everything again. Is there no way to update python? – Anurag Mar 15 '16 at 14:51
  • 2
    You can easily rebuild it. In the old venv, `pip freeze > /tmp/requirements.txt` save all what you've installed in a single file. In the new virtualenv, `pip install -r /tmp/requirements.txt` reinstall everything. – loutre Mar 15 '16 at 14:56
  • Its not just installing things, I am running supervisor, celery, flower, django, elastic search etc. Apart from installing them, I will need to setup all the configurations again which I want to avoid. – Anurag Mar 15 '16 at 15:00
  • 2
    Well your virtualenv folder should just be an execution context. In it you should find python/pip/... binaries and libraries. All your code and external parts should be somewhere else. – loutre Mar 15 '16 at 15:11
  • 1
    Agreed - a virtualenv directory should contain only python and things installed by pip. This is possibly a confusion when people say 'Run things in a virtualenv', and what 'in' means... – Simon Fraser Mar 15 '16 at 15:40