Tutorial :Problem with Python modules



Question:

I'm uploading my first Django app to my Dreamhost server. My app uses xlwt package and since I can't install it in the default location ( /usr/lib/python2.3/site-packages/xlwt ), I installed it on another location by:

python setup.py install --home=$HOME  

Then xlwt is installed here:

/home/myuser/lib/python/xlwt/  

After that, I add this folder to de env var PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/home/myuser/lib/python  

... And in a python promt I can do this (without problems)

import xlwt  

... But if I do the same thing in my app code, I have the follow error:

Could not import ISI.restaurante.views. Error was: No module named xlwt  

[where ISI.restaurante.views is my code where I do the import]

Could u help me? Thanks!


Solution:1

PYTHONPATH may only be set when you run from the shell, you can set path programatically from python using

import sys  sys.path.append('/home/myuser/lib/python')  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »