将完整的 virtualenv 复制到另一台电脑
问题描述
我有一个位于 /home/user/virtualenvs/Environment
的 virtualenv
.现在我需要在另一台 PC 上使用这个环境.所以我安装了 virtualenv-clone
并用它来克隆 /Environment
.然后我通过USB将它复制到另一台PC.我可以使用 source activate
激活它,但是当我尝试使用 sudo ./Environment/bin/python
启动 python 解释器时,我得到了
I have a virtualenv
located at /home/user/virtualenvs/Environment
. Now I need this environment at another PC. So I installed virtualenv-clone
and used it to clone /Environment
. Then I copied it to the other PC via USB. I can activate it with source activate
, but when I try to start the python interpreter with sudo ./Environment/bin/python
I get
./bin/python: 1: ./bin/python: Syntax Error: "(" unexpected
在没有 sudo 的情况下执行它会给我一个错误,告诉我二进制格式存在错误.但这怎么可能呢?我只是复制它.还是有更好的方法来做到这一点?我不能只使用 pip freeze
因为在 /Environment/lib/python2.7/site-packages/
中有一些包是我自己写的,我需要复制它们, 也.据我了解 pip freeze
只是创建一个包列表,然后 pip 下载并安装.
Executing it without sudo gives me an error telling me that there is an error in the binaries format.
But how can this be? I just copied it. Or is there a better way to do this? I can not just use pip freeze
because there are some packages in /Environment/lib/python2.7/site-packages/
which I wrote myself and I need to copy them, too. As I understand it pip freeze
just creates a list of packages which pip then downloads and installs.
解决方案
在源机器上执行以下步骤:
- 工作 [环境名称]
- pip freeze > requirements.txt
- 将 requirements.txt 复制到其他电脑
在另一台电脑上:
- 使用 mkvirtualenv [environment_name] 创建一个虚拟环境
- 工作 [环境名称]
- pip install -r requirements.txt
你应该完成了.
- 如何复制/克隆从服务器到本地机器的虚拟环境
相关文章