Skip to main content
gamedev.net
🔒 Locked

Python Module Import Question

Started by ZachBethel Aug 8, 2011 at 2:10 PM 0 replies 800+ views
Original Post
ZachBethel
ZachBethel
I have several years of programming experience, but I have been learning python recently and I'm having trouble understanding its import behavior. I've got a project with a namespace tree, and I've got a test file that I'm importing modules from the project into. Something like this: "import some.cool.thing as thing." Well, some/cool/thing.py then tries to import a local module some/cool/anotherthing.py using "import anotherthing" This fails with a "No module named anotherthing" error. It does not fail, however when I use "import some.cool.anotherthing." So basically it wants the fully qualified namespace path.

I didn't write the code, and there are dozens of imports like this that are done locally. Is there some setting I need to change to make python look in the local directory of the module that's doing the import? It seems like I shouldn't have to use the full namespace name for everything.

Thanks.
ZachBethel
ZachBethel
Well, just 20 minutes after posting this I figured out that I needed to edit the PYTHONPATH environment variable to match the directory.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.