eclipse pydev

编程入门 行业动态 更新时间:2024-10-25 10:28:19
eclipse pydev - 如何安装python模块(eclipse pydev - how to install python modules)

只是通过使用Python的(非常好的)书籍测试驱动开发工作。

这样就可以使用Python3.4。 顺便说一句,我在Windows 7操作系统中运行。

我已经使用一个简单的文本编辑器并从命令行运行所有的东西...在其中特别是我使用“pip install”安装Django和Selenium,按照书的说明。 这在... \ Python34 \ Lib \ site-packages \ ...下创建了文件夹“selenium”和“django”,所以我将这些添加到我的Eclipse / PyDev项目的PythonPath中。

选择了正确的解释器后,我尝试运行一个在命令行上正常运行的文件:“> python3 functional_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'

...对我来说,这看起来像一个依赖性的东西......好像“pip install”处理依赖性问题只是包含一个文件夹而不是。

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

几天后

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

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

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

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.

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'

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

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

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!

最满意答案

那么,pip install应该适用于PyDev(它应该自动识别依赖)...

即:在您的用例中,PYTHONPATH中应该唯一的文件夹是D:\ apps \ Python34 \ lib \ site-packages(并且pip应该将软件包安装到该文件夹​​ - 确保不添加额外的文件夹“D:\ apps \ Python34 \ lib \ site-packages \ django”以及PYTHONPATH的site-packages中的任何其他内容。

如果它仍然无法正常工作,请检查模块django.utils.six.moves.http_cookies是否确实在您预期的位置。 此外,您可以打印运行时使用的PYTHONPATH:

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

检查这是否真的是你所期望的。

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

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

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.

更多推荐

本文发布于:2023-04-29 01:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:eclipse   pydev

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!