python - Virtualenv 无法运行

标签 python django virtualenv pip

我已经使用以下命令构建了我的虚拟环境:

virtualenv env --distribute --no-site-packages

然后我用 pip 将几个模块(django 等)安装到 env 中,问题是当我想在第二台机器上运行代码时它不起作用,这是我所做的:

visgean@rewitaqia:~/scripty/project_name$ source ./env/bin/activate
(env)visgean@rewitaqia:~/scripty/project_name$ python
Python 2.7.1+ (r271:86832, Sep 27 2012, 21:12:17) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.__file__
'/home/visgean/scripty/project_name/env/lib/python2.7/site-packages/django/__init__.pyc'

但是当我想在第二台机器上运行它时:

(env)user@debian:~/project_name$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django
>>> 

我出现狂野错误!第一台机器是ubuntu,第二台机器是ubuntu。/home/user/project_name/env/lib/python2.7 中似乎有一些损坏的链接,这是问题所在吗?如果是这样,我应该如何预防/修复它?

最佳答案

如果您只是将 virtualenv 复制到第二台计算机,您可能会遇到一些问题。来自 virtualenv 站 pip :

Normally environments are tied to a specific path. That means that you cannot move an environment around or copy it to another computer. You can fix up an environment to make it relocatable with the command:

$ virtualenv --relocatable ENV

This will make some of the files created by setuptools or distribute use relative paths, and will change all the scripts to use activate_this.py instead of using the location of the Python interpreter to select the environment.

Note: you must run this after you've installed any packages into the environment. If you make an environment relocatable, then install a new package, you must run virtualenv --relocatable again.

关于python - Virtualenv 无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13057103/

相关文章:

python - 为什么这种测试回文的方法比使用 [::-1] 慢得多?

javascript - 当用户打开新选项卡或转到另一个选项卡时如何发出通知?

ubuntu - PkgResourcesDeprecationWarning : 0. 1.36ubuntu1 是无效版本,有没有人见过这个

python - conda 安装在 conda 创建的 virtualenv 中不起作用

python - Jedi-vim 自动补全 python3.6 virtualenv 不工作

python - 我应该在自己的 .py 文件中创建每个类吗?

python - Apache Beam python Bigquery 将流式插入更改为批量插入?

python - pandas 数据帧行的两两相等

python - Django : Foreign key set not found after saving object

javascript - 成功 AJAX 发布后重新渲染 HTML 模板片段或部分