eclipse pydev - how to install python modules

17.6k views Asked by At

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!

1

There are 1 answers

1
Fabio Zadrozny On BEST ANSWER

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.