蟒蛇 +姜戈 +虚拟环境视窗

发布于 2024-12-13 21:10:17 字数 1412 浏览 3 评论 0原文

我在安装 python + virtualenv + django 时遇到一些问题,需要帮助。

系统:Windows 7、64b

我做什么? 1) 安装Python 2.7.2 (32位) 2)安装SetupTools(32位) 3) 安装 VirtualEnv

E:\APPZ\Console2>C:\Python27\Scripts\easy_install.exe virtualenv

4) 创建 virtualenv:

E:\APPZ\Console2>virtualenv E:\CODE\wamp\www\AMBIENTES\env

5) 好的,现在我创建了一个“.bat”来使用我的 env 并将其放入 C:\Windows 中。

C:\Windows\python.bat

cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat

到目前为止一切顺利 现在我执行了 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.

现在,问题是:

(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>

-

有谁知道我能做什么?

I had some problem on installing python + virtualenv + django and need help.

System: Windows 7, 64b

What i do?
1) Installed Python 2.7.2 (32bits)
2) Installed SetupTools (32 bits)
3) Installed VirtualEnv

E:\APPZ\Console2>C:\Python27\Scripts\easy_install.exe virtualenv

4) Created 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.

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:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扛起拖把扫天下 2024-12-20 21:10:17

我知道这个问题已经很老了,对于作者来说可能不再实际了。但就它出现在谷歌顶部而言,我会留下对我有帮助的答案。

基本上,正确的答案是发布类似的问题

严格来说,当您执行 django-admin.py --version 时,会调用错误的 Python 安装。为了检查您在这种情况下使用的 Python,请在“命令行”中输入 ftype Python.File。如果不是 virtualenv,那么您可以重新关联默认的 Python:


ftype Python.File="E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe" "%1" %*

或者取消文件关联(从cmd.exe):

assoc .py=
ftype Python.File=

重新关联.py扩展程序后,您应该指定执行Python文件的完整路径:

E:\CODE\ wamp\www\AMBIENTES\env\Scripts\python.exe E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version

或者,如果您愿意,您可以编辑 virtualenv 的activate.bat 来放置特定的 .py 关联,使用上面提到的 assocftype 命令行实用程序。

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 posted for 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.File in "command line". If it's not the virtualenv's one, then you could reassociate the default Python:


ftype Python.File="E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe" "%1" %*

Or unset the file association (from cmd.exe):

assoc .py=
ftype Python.File=

After you reassociate the .py extension program, you should specify full path to execute Python files:

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.bat to put specific .py association, using assoc and ftype command line utils, mentioned above.

流星番茄 2024-12-20 21:10:17

我相信您的问题是,将 python setup.py install 与 Django 源一起使用是将 Django 安装在您的主 site-packages/dist-packages 路径中,而不是您的虚拟环境中。

相反,使用pip或easy_install:

$ pip install Django==1.2.7  --OR -- $ easy_install Django==1.2.7

如果你不能直接从PyPi(企业防火墙等)下载,你可以通过稍微修改命令来使用你已有的源:(

$ pip install -f file:///E/CODE/wamp/www/AMBIENTES/ Django==1.2.7

转换后的Windows路径可能需要一些调整。我认为这是对的,但已经有一段时间了)

I believe your problem is that using python setup.py install with the Django source is installing Django in your primary site-packages/dist-packages path instead of that of your virtual environment.

Instead, use pip or 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:

$ 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文