如何在python中重新创建虚拟环境 [英] How to recreate a virtual env in python
问题描述
我已经在 Ubuntu 16.04 上安装了 virtualenv 和 virtualenvwrapper我创建了一个名为 env1 的环境
I have installed virtualenv and virtualenvwrapper on Ubuntu 16.04 I have created one enviroment named env1
$ sudo apt-get install python-pip
$ pip install virtualenv
$ pip install --upgrade pip
$ pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv env1
进入 (env1) 后,我安装了几个软件包
Once in (env1) I have installed several packages
(env1) $ pip install numpy
(env1) $ pip install scipy
(env1) $ pip install matplotlib
(env1) $ apt-get install python-tk
我也安装了opencv3(因为太长了我就不复制了)
I have also installed opencv3 (I am not copying how because is too long)
我将 env1 用于特定项目.
I am using env1 for a specific project.
现在我想使用相同的包启动另一个项目,但我还想添加其他包.
Now I want to start another project using the same packages, but I also want to add other packages.
我已经创建了 env2,我想知道是否可以将 env1 复制到 env2 而无需从头开始重新安装所有东西.
I have created env2, and I was wondering if it is possible to copy env1 to env2 without the need to re-install everything again from scratch.
推荐答案
最好的选择是:
virtualenv-1:
virtualenv-1:
pip freeze > requirements.txt
virtualenv-2:
virtualenv-2:
pip install -r requirements.txt
假设它们都在同一个系统上并且使用相同的 Python,那么在某种程度上可以只复制站点包:
Assuming they are both the on the same system and use the same Python, it is somewhat possible to just copy the site-packages:
cp -Rp /environments/virtualenv-1/lib/python2.7/site-packages \
/environments/virtualenv-2/lib/python2.7/site-packages
但这不一定有效:
- 某些软件包会将依赖项和其他东西安装到/bin/或其他地方.大多数人不会,但很多人会.
- 如果 virtualenv 的 python 版本不同——即使是次要版本——这可能会破坏使用 c 扩展的库.
所以最好的办法是 pip freeze
并从该文件重新安装.
So your best bet is to pip freeze
and reinstall from that file.
这篇关于如何在python中重新创建虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!