10

I want to add all folders in my Pydev project to PYTHONPATH so that I can reap the benefits of easily seeing unused imports etc. To do this I seemingly have to add all folders manually including the subfolders, one by one. Is there any way to add them all at once (recursively) or am I doing this completely wrong?

Now I right click the project in the Navigator and select Preferences. From there I go to Pydev-PYTHONPATH and finally I can add the folders.

MdaG
  • 2,680
  • 2
  • 34
  • 46
  • 1
    If you add the top-level folder as a Source folder under PyDev - PYTHONPATH, doesn't that automatically add all packages under that folder to the PYTHONPATH for you? It works for me i.e. I get unused import warnings. Are you using the latest PyDev version? – Anshuman Bhaduri Dec 14 '11 at 00:07
  • I've been away from Eclipse for some time now. Mostly coding in Xcode. I'll look at the latest release of Eclipse and your question when I'm back to Eclipse. :-) – MdaG Dec 14 '11 at 10:35

3 Answers3

3

Ok, just to give a proper answer, you should just add the folder(s) that you want to be in the PYTHONPATH as your source folder(s).

So, if you have a structure such as

/myproject
/myproject/src
/myproject/package
/myproject/package/__init__.py
/myproject/package2
/myproject/package2/__init__.py

You'd only want to add /myproject/src as your PYTHONPATH.

If you really had multiple folders to add there, you could edit the .pydevproject file (which is at the root of your project) and add multiple folders there at once (although as noted, you should only have few folders there, so, this is generally not needed -- although sometimes you may want that if you're adding multiple libraries to a folder or something alike).

The PyDev FAQ explains this properly on the items listed below:

  • How do I import existing projects/sources into PyDev?

  • How do I import existing projects/sources for a Django project into PyDev?

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • 1
    In my version of eclipse, I just right click on the project and edit the properties. The PythonPath is one of the tabs. – sww314 Sep 12 '12 at 21:47
2

Check this out, this worked for me.

  1. if you get an error “unresolved import: pydevd” try saving the file ‘manage.py’ first. the error should go away.

  2. If the error persists: you need to make sure pydev is in your PYTHONPATH. a) Go to Eclipse>Preferences>PyDev>Python Interpreter: b) Click New Folder> (mac)”/Applications/Eclipse/plugins/org.python.pydev_x.x.x.x/pysrc”

c) Click “Apply” This adds the folder that contains pydevd.py to your PYTHONPATH. Eclipse automatically adds that to your project’s Python Library. This should resolve the problem and you can run it now.

https://djangounchain.files.wordpress.com/2012/12/screen-shot-2013-01-06-at-3-49-02-pm.png

mihir
  • 21
  • 1
  • This is the correct answer. Please note that Eclipse and PyDev have changed versions since then. For me, the feature was in Eclipse > Preferences > PyDev > Interpreters > Python Interpreter. Then on the bottom half of the dialog, click the "Libraries" tab and "New Folder". Hunt around. You should find this feature somewhere or another under PyDev .. Interpreters. – horace Dec 26 '22 at 21:51
0

(This should be a Comment to Fabio's answer, but insufficient rep)

(PyDev 2.7.1.2012100913)

Adding folders to the PythonPath does not work for EFS/Remote folders (rse://...)

When you click 'Apply' gives:

An internal error occurred during: "Python Nature: rebuilding modules".
java.lang.NullPointerException
MikeW
  • 5,504
  • 1
  • 34
  • 29
  • Try using WebDAV and mapping it as a drive in your Windows or mounting as directory in Linux. That's how I know develop remotely instead of RSE. See sample apache conf file here that I use: http://danielsokolowski.blogspot.ca/2013/02/windows-webdav-double-authentication.html – Daniel Sokolowski Mar 12 '13 at 19:55