How to backup/restor python virtualenv?

我与影子孤独终老i 提交于 2019-12-11 10:46:54

问题


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.


回答1:


rdiff-backup normally copies symlinks as they are and does not reference them. Did you maybe add the --include-symlinks option ?

"cp -p" or "rsync -a" would also preserve symlinks.




回答2:


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


来源:https://stackoverflow.com/questions/35680162/how-to-backup-restor-python-virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!