2
votes

I have a directory structure :

../POC/mud/
            client/
            common/
            server/

and i am trying to use the following imports :

from mud.server import config
from mud.common.lib import util

but when i try to import config , i get an error:

Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mud.server import config
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named mud.server
>>> from mud.common.lib import util
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named mud.common.lib
>>> 

Do i need to be in a certain location for imports to work, or the modules need to be compiled on the OS ? these "mud" modules are just a collection of python .py files

1
Did you look in to the init.py. The module owner can decide on what module needs to be imported. I am very sure that the problem is in your init.py. :) - uncaught_exceptions
Where are you running from? Can you import just mud? - cledoux
>>> from mud.server import config >>> from mud.common.lib import util >>> print os.getcwd() /home/kahmed/POC/MUD >>> Thanks - kamal

1 Answers

5
votes

First you have to have __init__.py file in the mud and sub-folders, the file can be empty though. Take a look at the Python tutorial in the packages section: http://docs.python.org/tutorial/modules.html#packages

In addtion you need to be in the POC folder for the import statements to work or you set the PYTHONPATH env var accordingly or update sys.path dynamically.