PYTHONPATH breaks MySQLdb

A

Aljosa Mohorovic

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
 
D

Diez B. Roggisch

Aljosa said:
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
 

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

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top