PYTHONPATH problems

T

Tim Isakson

OK - I just checked Programming Python out from the library, and am
enjoying seeing the examples (I've dabbled in Python some previously, but
an trying to expand my knowledge a bit).

I'm having a problem getting the PYTHONPATH to work - I've got the
variable set in the shell (and exported), and it's showing up when I do
this:

-- Begin --
Python 2.2.2 (#2, Feb 5 2003, 10:40:08) [GCC 3.2.1 (Mandrake Linux 9.1
3.2.1-5mdk)] on linux-i386 Type "help", "copyright", "credits" or
"license" for more information.['', '/home/tim/python/PP/Examples', '/usr/lib/python2.2',
'/usr/lib/python2.2/plat-linux-i386', '/usr/lib/python2.2/lib-tk',
'/usr/lib/python2.2/lib-dynload', '/usr/lib/python2.2/site-packages']-- End --

However, it isn't finding any of the modules in the directory tree that
begins under /home/tim/python/PP/Examples (it's not having any problems
with the standard modules - as evidenced by the import of sys above).

I'm at a loss - any thoughts on what I'm doing incorrectly?

Thanks for any assistance!

Tim
 
E

Erik Max Francis

Tim said:
However, it isn't finding any of the modules in the directory tree
that
begins under /home/tim/python/PP/Examples (it's not having any
problems
with the standard modules - as evidenced by the import of sys above).

We'll need to see the files contained therein, what their permissions
are, and what their contents are. Do they have the right permissions?
Do they end in .py? Are you importing the module exactly as it is name
(less the .py extension)?

--
Erik Max Francis && (e-mail address removed) && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ Sometimes there's no point in giving up.
-- Louis Wu
 
R

Rene Pijlman

Tim Isakson:
I'm having a problem getting the PYTHONPATH to work - I've got the
variable set in the shell (and exported), and it's showing up when I do
this:

So why do you think the problem has to do with PYTHONPATH? Perhaps there's
something wrong with your import statement, the name of the files, ...
Tell us more.
 
F

Fredrik Lundh

Tim said:
However, it isn't finding any of the modules in the directory tree that
begins under /home/tim/python/PP/Examples (it's not having any problems
with the standard modules - as evidenced by the import of sys above).

"sys" is a built-in module; Python finds that one without even looking
at the path.
I'm at a loss - any thoughts on what I'm doing incorrectly?

Thanks for any assistance!

running Python with the "-vv" flag might provide you with some
additional clues:

$ python -vv # trying mymodule.so
# trying mymodulemodule.so
# trying mymodule.py
# trying mymodule.pyc
# trying /mysystem/lib/python2.1/mymodule.so
# trying /mysystem/lib/python2.1/mymodulemodule.so
/.../
# trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.py
# trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.pyc
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named mymodule

(also note that you must have read access to the scripts; if Python
cannot read a file, it treats it as if it didn't exist)

</F>
 
T

Tim Isakson

"sys" is a built-in module; Python finds that one without even looking at
the path.


running Python with the "-vv" flag might provide you with some additional
clues:

$ python -vv
# trying mymodule.so
# trying mymodulemodule.so
# trying mymodule.py
# trying mymodule.pyc
# trying /mysystem/lib/python2.1/mymodule.so # trying
/mysystem/lib/python2.1/mymodulemodule.so /.../
# trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.py #
trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.pyc
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named mymodule

(also note that you must have read access to the scripts; if Python cannot
read a file, it treats it as if it didn't exist)

</F>

Thanks for the -vv flag tip - it helped some.

Sadly (for me, at least), the problem turned out to be user error - I was
using BASH syntax for the path while within Python, and needless to say,
that didn't do the trick.

Once I changed the imports to use '.' as the delimiter, things worked
fine.

Thanks for your assistance!

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,927
Members
47,469
Latest member
benny001

Latest Threads

Top