如何安装python模块

如何安装python模块

本文介绍了eclipse pydev-如何安装python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照我的方式(非常好)完成一本书,即使用Python进行测试驱动开发".

Just working my way through a (very good) book call Test Driven Development using Python.

顺便说一下,这利用了Python3.4.顺便说一下,我正在Windows 7操作系统中运行.

This makes use of Python3.4 by the way. By the way, I am running in a Windows 7 OS.

我已经使用简单的文本编辑器并从命令行运行了所有内容……在此过程中,特别是按照书中的说明,我使用"pip install"安装了Django和Selenium.这样在... \ Python34 \ Lib \ site-packages \ ...下创建了文件夹"selenium"和"django",因此我将它们添加到了Eclipse/PyDev项目的PythonPath中.

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.

选择正确的解释器后,我然后尝试运行在命令行上运行良好的文件:> python3functional_tests.py" ...但我得到

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

  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'

...在我看来,这似乎是一个依赖项...好像"pip install"以某种方式处理依赖项一样,只包含一个文件夹就不会.

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

问题归结为:使用PyDev安装python模块的正确"方法是什么?

Question boils down to this: what's the "proper" way to install a python module using PyDev?

几天后

several days later

哇...什么都没有?没有!我想这必须意味着您要么必须手动添加依赖项,要么在Eclipse本身中使用诸如Ant,Maven或Gradle之类的东西.即使在IDE之外,后者也不是我的强项.从PyDev专家那里得到答案还是很高兴的!

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!

推荐答案

好了,pip安装应该适用于PyDev(它应该自动识别依赖项)...

Well, pip install should work for PyDev (it should automatically recognize the dependency)...

即:在您的用例中,应该在PYTHONPATH中的唯一文件夹是D:\ apps \ Python34 \ lib \ site-packages(并且pip应该将软件包安装到该文件夹​​中-确保您不添加"D:\ apps \ Python34 \ lib \ site-packages \ django"的额外文件夹,或指向PYTHONPATH的站点包中的其他文件夹).

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

如果它仍然无法正常工作,请检查模块django.utils.six.moves.http_cookies是否确实在您期望的位置.另外,您可以使用以下命令打印在运行时使用的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:

import sys
print('\n'.join(sorted(sys.path)))

检查这是否真的是您所期望的.

To check if that's really what you expect.

这篇关于eclipse pydev-如何安装python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:45