468,133 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

PYTHONPATH breaks MySQLdb

i have a working MySQLdb module (/usr/lib/python2.4/site-packages/
MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems.

"clean shell" after login:
python -c "import MySQLdb" reports no errors

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal

python -c "import MySQLdb" reports no errors as in previous case

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal/apps

i get this:
python -c "import MySQLdb"
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named MySQLdb

is there any reason why this happens?

Aljosa Mohorovic
Jun 27 '08 #1
1 1495
Aljosa Mohorovic schrieb:
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/
MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems.

"clean shell" after login:
python -c "import MySQLdb" reports no errors

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal

python -c "import MySQLdb" reports no errors as in previous case

if i export PYTHONPATH:
export PYTHONPATH=/var/www/projects/uv_portal/portal/apps

i get this:
python -c "import MySQLdb"
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named MySQLdb

is there any reason why this happens?
Yes. You found a secret that nobody was supposed to know: Python doesn't
allow portal applications te be written! So it scans the pythonpath for
a suffix of "portal/apps", and refuses to import anything if it finds it.

Seriously: yes, there must be a reason, but nobody can tell because we
don't know & see what is beyond the apps-dir that might cause trouble.
Generally speaking, given that you can properly import MySQLdb without
any path set, you need to see if there is anything in your path that
somehow gets imported first and e.g. alters the sys.path.

Try

python -vc 'import MySQLdb'

and if that doesn't make things clearer, use strace.

Diez
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dave Harrison | last post: by
1 post views Thread by Peter Nikolaidis | last post: by
1 post views Thread by Derek Fountain | last post: by
8 posts views Thread by Tero Pihlajakoski | last post: by
1 post views Thread by Steve | last post: by
reply views Thread by Michael Yanowitz | last post: by
1 post views Thread by Yi Xing | last post: by
reply views Thread by Steve Holden | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.