Diez B. Roggisch deets at
Fri Apr 25 15:02:29 CEST 2008

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.


python -vc 'import MySQLdb'

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


More information about the Python-list mailing list