Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a Python virtualenv? [duplicate]

It would be really convenient to be able to update a virtual environment produced with virtualenv --system-site-packages /path/to/myvirtenv taking into account changes that have been done in the base Python.

For example, if IPython 2.4 has been installed in the virtualenv and IPython 3.0 has later been installed in the base Python, the old IPython should be removed from the virtual environment and replaced by a copy of the newer package.

How can we do this? Is there already a command to do this? If not, would it be possible to implement it in the package virtualenv?

PS: Working with virtual environments produced with the --system-site-packages option is very convenient when you do not have admin privileges but if any modifications to the base Python make the virtual env buggy, it does not seem to be a good method!

PS: This issue is related to this question virtualenv not finding updated module.

like image 407
paugier Avatar asked Jan 09 '23 19:01

paugier


1 Answers

if IPython 2.4 has been installed in the virtualenv and IPython 3.0 has later been installed in the base Python, the old IPython should be removed from the virtual environment and replaced by a copy of the newer package.

You might be able to tweak an existing virtualenv, e.g. by creating a new and copying files into the existing one. However, I find the best and safe way to update is as follows:

# preserve installed packages
source /path/to/venv/bin/activate
pip freeze > requirements.txt
deactivate
# careful now, this destroys all
rm -rf /path/to/venv

Then create a new virtualenv

# apply base changes
virtualenv --system-site-packages /path/to/venv
source /path/to/venv/bin/activate
pip install -r requirements.txt
like image 77
miraculixx Avatar answered Jan 18 '23 06:01

miraculixx