tags:

views:

744

answers:

2

Newbie question (I'm just getting started with Python and Pydev):

I've created a project "Playground" with (standard?) src/root sub-folder. In there I've created example.py.

How do I import my "example" module into Pydev's interactive console? ">>> import example" gives: "ImportError: No module named example"

+2  A: 

You need to set your PYTHONPATH accordingly (Google search is your friend) or use *.pth in your installation site-packages directory pointing to your project path. Don't forget to set your interpreter details with Pydev (Window->Preferences->Pydev->interpreter).

jldupont
So, just to be clear, Pydev doesn't do anything automatic to help me call me project code from its interactive console? I have to append to the PYTHONPATH environment variable for every new Pydev project I start?If so, maybe I'm asking the wrong question. What's the most convenient way to call a method of a project module when using Pydev?
David Easley
I can't be sure 100% because I have given up some time ago in using the integrated console: I'd rather use a separate system console to make sure things are *really* correct ;-) In any case, I was introduced to a nice way to setup my Python/Eclipse dev environment recently which might interest you (instead of waiting for Pydev to catch up): http://stackoverflow.com/questions/1522867/python-how-do-you-setup-your-workspace-on-ubuntu
jldupont
+1  A: 

I found the answer on the Plone website: Setting up PYTHONPATH in Eclipse project. This provides a convenient way to set PYTHONPATH on a per project basis. In my case I added "/Playground/src/root" to the Source Folders list. ">>> import example" then worked. (I'm still surprised project files aren't imported by default, though.)

Thank you jldupont for pointing me in the right direction (re. PYTHONPATH)!

David Easley