Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update existing virtualenv to use Python 3.6 [duplicate]

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.

like image 843
Cheng Avatar asked Jun 13 '17 03:06

Cheng


1 Answers

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
like image 69
Anthony Sottile Avatar answered Sep 30 '22 16:09

Anthony Sottile