1. /usr/Lib/python2.5 OR /usr/Lib/python2.5/site-packages OR (for specialized modules) in the same directory as the files that will use them.
2. It's probably a file permissions problem.
Jeff
jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
I always tend to stick the main program one directory above all the other modules. My directory tree will look something like this:
Gork/
gork.py
README
...
images/
title.tga
player1.tga
player2.tga
...
modules/
__init__.py
gameboard.py
globals.py
tga32.py
widgets.py
...
And so on. Obviously, "gameboard.py", etc. are the modules. I've wrapped them in a subdirectory-module. To use them, I import them in gork.py thus:
from modules.globals import *
import modules.widgets
...
Hope this helps.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
You can put them in a directory in the PYTHONPATH, so Python can find it (be careful with that one):
# show PYTHONPATH
import sys
print sys.path
Or better, add your own module directory (let's say MyModules) to PYTHONPATH. You have to add this all your programs that import one of your modules then:
import sys
sys.path.append(r'C:\Python25\MyModules')
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
sys.path is just the search path that the system uses to look up files whose full pathname is not given.
That is, a statement like
import mymodule1
will search the directories in sys.path for mymodule1.py.
So by itself, your statement would not create a directory. Rather, it would tell Python to add that directory to the list of paths to search.
Try this:
import os
os.mkdir("/media/disk/usr/lib/python2.5/MyModules")
That should make a directory.
BTW, "/media/disk/..." -- your copy of Python isn't on CD-ROM or some other read-only media, is it?
Jeff
jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
Jeff is right, your module directory has to exist with the module(s) you want to import already in it.
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213