如何在eclipse安装python_eclipse pydev-如何安装python模块

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

from django.http.cookie import SimpleCookie, parse_cookie

File "D:\apps\Python34\lib\site-packages\django\http\cookie.py", line 5, in

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!

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值