469,338 Members | 8,615 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

import vs. subdirectory search

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
Jan 18 '07 #1
2 1952
"John Nagle" <na***@animats.comescribió en el mensaje
news:45**************@animats.com...
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.
And should *not* be searched, unless the importing module is itself in the
M2Crypto directory.
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.
You *could* do: from M2Crypto import SSL, but I think this is not your
problem.
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?
No, it should not work as you describe it. Either you have another SSL
module in another place, or sys.path includes the M2Crypto directory.
On your 2.4 Windows, try this:
import sys
import SSL
print SSL.__file__
print sys.path
and see what happens

Jan 18 '07 #2
John try this:

from M2Crypto import SSL

That should put your SSL module in the namespace as you want.

--gordy

Jan 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by AckbarJedi | last post: by
5 posts views Thread by Colin Brown | last post: by
4 posts views Thread by Matt Whiteley | last post: by
43 posts views Thread by Dan Perl | last post: by
3 posts views Thread by Olivier Noblanc ATOUSOFT | last post: by
3 posts views Thread by David Jackson | last post: by
reply views Thread by =?Utf-8?B?Qm9ubmll?= | last post: by
reply views Thread by =?Utf-8?B?bW9iaWxlbW9iaWxl?= | last post: by
8 posts views Thread by tow | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.