Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to backup/restor python virtualenv?

A python virtualenv is full of symlinks:

$ virtualenv venv
Running virtualenv with interpreter /usr/bin/python2
New python executable in venv/bin/python2
Also creating executable in venv/bin/python
Installing setuptools, pip...done.
$ tree venv/lib/
venv/lib/
├── python2.7
│   ├── _abcoll.py -> /usr/lib/python2.7/_abcoll.py
│   ├── _abcoll.pyc
│   ├── abc.py -> /usr/lib/python2.7/abc.py
│   ├── abc.pyc
│   ├── codecs.py -> /usr/lib/python2.7/codecs.py
│   ├── codecs.pyc
│   ├── copy_reg.py -> /usr/lib/python2.7/copy_reg.py
│   ├── copy_reg.pyc
│   ├── distutils
│   │   ├── distutils.cfg
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── encodings -> /usr/lib/python2.7/encodings
│   ├── fnmatch.py -> /usr/lib/python2.7/fnmatch.py
│   ├── fnmatch.pyc
│   ├── genericpath.py -> /usr/lib/python2.7/genericpath.py
│   ├── genericpath.pyc

What is the recommended way to backup/restor them ?

My first attempt using rdiff-backup has derefence all symbolic links when I restor backup back.

like image 395
user3313834 Avatar asked Jul 13 '26 18:07

user3313834


1 Answers

Its easy to just freeze the environment into a text file and install from it later!

pip freeze > requirements.txt

then when you want to install

pip install -r requirements.txt
like image 85
Nagashayan Avatar answered Jul 15 '26 09:07

Nagashayan