9

I have an existing virtualenv called 'edge'. It uses Python 3.5.2. I have upgrade my Python interpreter to 3.6 and I want the 'edge` env to use 3.6 instead.

What command should I used to update edge's interpreter?

I searched on SO but all the answers I can find are for creating a new env. In my case, I don't want to create a new env.

Cheng
  • 16,824
  • 23
  • 74
  • 104
  • 4
    All binary packages installed for python3.5 are not compatible with python3.6 -- your best bet is to `edge/bin/pip freeze > reqs.txt && virtualenv edge2 -ppython3.6 && edge2/bin/pip install reqs.txt` – anthony sottile Jun 13 '17 at 03:48
  • thx @AnthonySottile do you mind to write an answer so that I can accept it? – Cheng Jun 13 '17 at 05:18

1 Answers1

10

All binary packages installed for python3.5 (for example numpy or simplejson) are not compatible with python3.6 (they are not abi compatible). As such, you can't upgrade / downgrade a virtualenv to a different version of python.

Your best bet would be to create a new virtualenv based on the packages installed in the original virtualenv. You can get close by doing the following

edge/bin/pip freeze > reqs.txt
virtualenv edge2 -p python3.6
edge2/bin/pip install -r reqs.txt

Note that virtualenvs generally aren't movable, so if you want it to exist at edge you'll probably want the following procedure instead

edge/bin/pip freeze > reqs.txt
mv edge edge_old
virtualenv edge -p python3.6
edge/bin/pip install -r reqs.txt
# optionally: rm -rf edge_old
anthony sottile
  • 61,815
  • 15
  • 148
  • 207