eclipse pydev - 如何安装python模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30833283/
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
eclipse pydev - how to install python modules
提问by mike rodent
Just working my way through a (very good) book call Test Driven Development using Python.
只是通过(非常好的)书籍调用使用 Python 进行测试驱动开发。
This makes use of Python3.4 by the way. By the way, I am running in a Windows 7 OS.
顺便说一下,这使用了 Python3.4。顺便说一下,我在 Windows 7 操作系统中运行。
I've got all the stuff working using a simple text editor and running from the command line... in the course of which in particular I used "pip install" to install Django and Selenium, as per book's instructions. This created folders "selenium" and "django" under ...\Python34\Lib\site-packages\ ... so I added these to the PythonPath for my Eclipse/PyDev project.
我已经使用简单的文本编辑器完成了所有工作,并从命令行运行......在此过程中,我特别使用“pip install”来安装 Django 和 Selenium,按照书中的说明。这在 ...\Python34\Lib\site-packages\ 下创建了文件夹“selenium”和“django”...所以我将它们添加到我的 Eclipse/PyDev 项目的 PythonPath 中。
With the correct interpreter selected I then tried to run a file which runs fine on the command line: "> python3 functional_tests.py"... but I get
选择正确的解释器后,我尝试运行一个在命令行上运行良好的文件:"> python3functional_tests.py"...但我得到了
File "D:\apps\Python34\lib\site-packages\django\http\__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
File "D:\apps\Python34\lib\site-packages\django\http\cookie.py", line 5, in <module>
from django.utils.six.moves import http_cookies
ImportError: cannot import name 'http_cookies'
... to me this looks like a dependency thing... as though "pip install" handles dependency matters in a way just including a single folder doesn't.
...对我来说,这看起来像是一个依赖项...好像“pip install”以一种仅包含单个文件夹的方式处理依赖项问题。
Question boils down to this: what's the "proper" way to install a python module using PyDev?
问题归结为:使用 PyDev 安装 python 模块的“正确”方法是什么?
several days later
几天后
wow... nothing? Nothing! I suppose this must mean that you either have to add dependencies manually or use something like Ant, Maven or Gradle within Eclipse itself. These latter are not my strong areas, even outside an IDE. Would still be nice to have an answer from a PyDev expert!
哇……什么都没有?没有!我想这一定意味着您要么必须手动添加依赖项,要么在 Eclipse 本身中使用诸如 Ant、Maven 或 Gradle 之类的东西。后者不是我的强项,即使在 IDE 之外。从 PyDev 专家那里得到答案仍然很高兴!
采纳答案by Fabio Zadrozny
Well, pip install should work for PyDev (it should automatically recognize the dependency)...
好吧,pip install 应该适用于 PyDev(它应该自动识别依赖项)...
I.e.: in your use case, the only folder that should be in the PYTHONPATH is D:\apps\Python34\lib\site-packages (and pip should install packages to that folder -- make sure you don't add extra folders for "D:\apps\Python34\lib\site-packages\django" nor anything else inside the site-packages to the PYTHONPATH).
即:在您的用例中,应该在 PYTHONPATH 中的唯一文件夹是 D:\apps\Python34\lib\site-packages(并且 pip 应该将包安装到该文件夹中——确保您没有为“D:\apps\Python34\lib\site-packages\django”或站点包内的任何其他内容到 PYTHONPATH)。
If it's still not working, please check if the module django.utils.six.moves.http_cookies is indeed where you expect it to be. Also, you can print the PYTHONPATH being used in runtime with:
如果它仍然不起作用,请检查模块 django.utils.six.moves.http_cookies 是否确实是您期望的位置。此外,您可以使用以下命令打印在运行时使用的 PYTHONPATH:
import sys
print('\n'.join(sorted(sys.path)))
To check if that's really what you expect.
检查这是否真的是您所期望的。