在 Windows 上,我运行 python 程序时未使用 virtualenv
我在 Windows 上安装了 virtualenv。
在 cmd 中,我运行 python 并查看 sys.path 并查看包含的 virtualenv 路径。
但是当我运行manage.py(对于django)时,我没有看到virtualenv路径, 所以 virtualenv 不能与 django 服务器一起使用。
为什么?
I have virtualenv installed on windows.
In cmd, i run python and look at sys.path and see the virtualenv path included.
but when i run manage.py (for django), I don't see the virtualenv path,
so virtualenv is not working with django server.
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Virtualenv 修改 PATH 以包含具有正确设置的 Python。它是一个与Python系统完全独立的程序。
PATH 用于按名称查找程序:执行 PATH 中给定名称的第一个程序。
当您“运行文件”时,Windows 使用文件的扩展名来查找要运行的程序。它不会通过程序名称进行查找,因此不会检查 PATH。
解决方案是在 virtualenv 处于活动状态时从命令行 (
python manage.py
) 显式调用 Python。这样,Windows 将在 PATH 中搜索“python”的含义,并找到正确的路径。Virtualenv modifies the PATH to include a Python with the correct setup. It's a completely separate program from the system Python.
The PATH is used to look up programs by name: the first program of a given name that's in the PATH gets executed.
When you “run a file”, Windows uses the extension of the file to look up a program to run. It doesn't look it up by the name of the program, and so doesn't check the PATH.
The solution is to explicitly invoke Python from the command line (
python manage.py
) while a virtualenv is active. This way, Windows will search PATH for what you meant by “python”, and find the correct one.你做了吗:
?
have you done:
?
解决方案是通过使用显式调用 python: python file.py
如 http://www.velocityreviews.com/forums/t727997-problems-running-virtualenv-under-windows.html
由于某种原因,在windows中用.py注册的python没有调用虚拟环境。
the solution is to explicitly invoke python by using: python file.py
as described in http://www.velocityreviews.com/forums/t727997-problems-running-virtualenv-under-windows.html
for some reason, the python registered with .py in windows does not invoke virtualenv.