Python + Django + VirtualEnv + Windows
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8012956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python + Django + VirtualEnv + Windows
提问by Max Ferreira
I had some problem on installing python + virtualenv + django and need help.
我在安装 python + virtualenv + django 时遇到了一些问题,需要帮助。
System: Windows 7, 64b
系统:Windows 7、64b
What i do? 1) Installed Python 2.7.2 (32bits) 2) Installed SetupTools (32 bits) 3) Installed VirtualEnv
我所做的? 1) 安装 Python 2.7.2 (32 位) 2) 安装 SetupTools (32 位) 3) 安装 VirtualEnv
E:\APPZ\Console2>C:\Python27\Scripts\easy_install.exe virtualenv
4) Created virtualenv:
4)创建virtualenv:
E:\APPZ\Console2>virtualenv E:\CODE\wamp\www\AMBIENTES\env
5) Fine, now I created a ".bat" to use my env and put then in C:\Windows.
5) 很好,现在我创建了一个“.bat”来使用我的 env,然后放在 C:\Windows 中。
C:\Windows\python.bat
C:\Windows\python.bat
cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat
So far so good Now I executed the python.bat and installed django:
到目前为止一切顺利现在我执行了 python.bat 并安装了 django:
E:\APPZ\Console2>python
E:\APPZ\Console2>cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat
(env) E:\APPZ\Console2>cd E:\CODE\wamp\www\AMBIENTES\Django-1.2.7
(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>python setup.py install
django installed (1.2.7) successfully.
And now, the problem:
现在,问题是:
(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version
Traceback (most recent call last):
File "E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py", line 2, in <module>
from django.core import management
ImportError: No module named django.core
(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>
-
——
Does anyone know what I can do about it?
有谁知道我能做些什么?
回答by ajukraine
I know this question is old and maybe not actual anymore for author. But as far as it appears at Google's top, I would leave the answer that helped me.
我知道这个问题很老,对于作者来说可能不再实际了。但就它出现在谷歌的顶部而言,我会留下对我有帮助的答案。
Basically the correct answer is postedfor the similar question.
Strictly speaking the wrong Python installation is called when you execute django-admin.py --version. in order to check which Python you use in the case, type ftype Python.Filein "command line". If it's not the virtualenv's one, then you could reassociate the default Python:
严格来说,当您执行django-admin.py --version. 为了检查您在案例中使用的 Python,请输入ftype Python.File“命令行”。如果它不是 virtualenv 的,那么您可以重新关联默认的 Python:
ftype Python.File="E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe" "%1" %*
ftype Python.File="E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe" "%1" %*
Or unset the file association (from cmd.exe):
或取消设置文件关联(来自 cmd.exe):
assoc .py=
ftype Python.File=
After you reassociate the .pyextension program, you should specify full path to execute Python files:
重新关联.py扩展程序后,应指定执行 Python 文件的完整路径:
E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version
E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version
Or if you want, you could edit virtualenv's activate.batto put specific .pyassociation, using assocand ftypecommand line utils, mentioned above.
或者,如果你愿意,你可以编辑的virtualenv的activate.bat将特定的.py关联,使用assoc和ftype命令行utils的,上面提到的。
回答by Chris Pratt
I believe your problem is that using python setup.py installwith the Django source is installing Django in your primary site-packages/dist-packages path instead of that of your virtual environment.
我相信您的问题是python setup.py install与 Django 源一起使用是在您的主要站点包/dist-packages 路径而不是您的虚拟环境中安装 Django。
Instead, use pip or easy_install:
相反,使用 pip 或 easy_install:
$ pip install Django==1.2.7 --OR -- $ easy_install Django==1.2.7
If you can't directly download from PyPi (corporate firewall, etc.) you can use the source you already have by modifying the command slightly:
如果你不能直接从PyPi(企业防火墙等)下载,你可以通过稍微修改命令来使用你已经拥有的源:
$ pip install -f file:///E/CODE/wamp/www/AMBIENTES/ Django==1.2.7
(Converted Windows path may need some tweaking. I think that's right, but it's been awhile)
(转换后的 Windows 路径可能需要一些调整。我认为是对的,但已经有一段时间了)

