import vs. subdirectory search

John Nagle nagle at animats.com
Wed Jan 17 20:32:20 EST 2007


Some obscure import issues:

    I'm running Python 2.3.4 from a CGI script on a shared hosting Linux system.
The CGI program is being executed from Apache, as "nobody".  I have some
local modules installed in "~myname/lib/python"; these include
"MySQLdb" and "M2Crypto".

    Since this is running as "nobody", I append

	/home/myname/lib/python

to sys.path.

    Within the CGI programs,

	import MySQLdb				# works fine
	import M2Crypto				# works fine
	import SSL				# "No module named SSL"

The problem is that SSL is in a subdirectory of the M2Crypto directory,
and that's not being searched.  I can execute "import M2Crypto.SSL",
but that doesn't have the same effect; it puts SSL in a different
place in the namespace.  I'm trying to avoid that; it causes obscure
aliasing problems.

    On Python 2.4 under Windows 2000, importing from a subdirectory
appears to work.  Is that a Python 2.3.4 thing, or a Linux thing,
or something else?

    (The idea is to be able to run (mostly) the same Python code on Windows, for
test, and Linux, for production.)

				John Nagle



More information about the Python-list mailing list