如何在 virtualenv 中使用 pip 在 eclipse 中设置 PyDev 的 python 解释器
我想使用 pip 安装新软件包,他们说 安装 pip虚拟环境。我这样做并安装了一些软件包并使用它们没有问题。
但是我在使用 python2.7 在 PyDev 下设置简单的谷歌应用程序引擎 helloworld 应用程序时遇到问题。我将其设置为使用 C:\Python27\env\Scripts\python.exe。但运行它会出现错误,无法导入 pdb。
从 cmd 行运行 virtualenv python 并调用“import pdb”没有出现错误。并输入 pdb 回显:module 'pdb' from 'C:\Python27\lib\pdb.py'。因此,从 cmd 行,它可以在 root lib 目录中找到 pdb。 appengine 的调试表明它正在使用 virtualenv python。在设置 PyDev 解释器时,我确保系统 PYTHONPATH 中有 C:\Python27\lib,但这并不重要。奇怪的。 (我还有 C:\Python27\DLLs 和 C:\Python27\lib\lib-tk)。
所以我尝试使用 root python exe 作为解释器,它工作得很好。 pdb没有问题,所以我的代码是正确的。但现在它找不到我在 virtualenv 中使用 pip 添加的模块。
似乎有 3 个选项可以正确设置:
- 以某种方式使用 virtualenv python 设置 PyDev python 解释器,它将找到根 pdb 包。 (不知道如何做到这一点,但这似乎是正确的答案。)
- 或者使用 root python 并将 virtualenv 站点包添加到我的路径是否有效。 (不确定这是否有效)。
- 不要听从 pip 建议 - 在根环境中安装 pip 并在根环境中安装我的模块。
我希望以前经历过此问题的人能够提供一些建议,以了解以后处理最少问题的最佳方法。
I want to use pip to install new packages and they say to install pip in a virtualenv. I did that and installed some packages and use them no problem.
But I have a problem setting up the simple google app engine helloworld app under PyDev using python2.7. I set it up to use C:\Python27\env\Scripts\python.exe. But running it gave an error that it couldn't import pdb.
Running the virtualenv python from the cmd line and calling 'import pdb' gave no errors. And typing pdb echoed: module 'pdb' from 'C:\Python27\lib\pdb.py'. So from the cmd line, it could find pdb in the root lib dir. The debug out from appengine said it was using the virtualenv python. I made sure that I had C:\Python27\lib in the System PYTHONPATH when setting up the PyDev interpreter, but this did not matter. Strange. (I also have C:\Python27\DLLs and C:\Python27\lib\lib-tk).
So I tried using the root python exe as the interpreter and it works fine. No problem with pdb, so my code is correct. But now it can't find the modules I added using pip in the virtualenv.
It seems there are 3 options for setting this up correctly:
- Somehow setup the PyDev python interpreter using the virtualenv python that will find the root pdb package. (Don't know how to do this, but it seems like the right answer.)
- Or will it work to use the root python and add the virtualenv site-packages to my path. (not sure if this will work).
- Don't listen to the pip advice - install pip in the root env and install my modules in the root env.
I hope someone who has gone through this before can give some advice as to the best way to proceed with the least amount of problems later.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 google-appengine-python 小组做了一些研究,他们说采用选项 3:与 google appengine 一起使用时不要听 pip 建议。 appengine 与 virtualenv 的配合不佳。
参考文献:
带有 virtualenv 的 Appengine
开发服务器中的奇怪导入(和警告)
I did some research on the google-appengine-python group and they say to go with option 3: Don't listen to the pip advice when using it with google appengine. appengine does not play nice with virtualenv.
Refs:
Appengine with virtualenv
Strange imports (and WARNINGs) in development server