I am running an Ubuntu 14.4 and I have installed a python virtual environment.
Then I pip installed several python libraries (gdal, lxml, psycopg2 etc.)
Also in my system I have the module for QGIS.
So when I type python then I can import this module as:
import qgis.core
But when I try to do the same through my virtualenv I get an error: module not found.
When I created the virtualenv I did with the option:
virtualenv --no-site-packages env
Which restricts my env from the system's env. The question is how to access QGIS module in my virtualenv?
Best Answer
After create and activate your virtualenv :
You have to defined the PYTHONPATH environnement variable to your QGIS's python installation path.
please change [qgispath] to your qgis's path :
it will also be necessary to set LD_LIBRARY_PATH
to prevent this error
Your pythonpath is set only for the virtualenv, and for your session. If you want to set it automatically under this virtualenv, you can create a file under
env/lib/python2.7/site-packages
with a .pth file.to create and populate the file use a command like that :
Found in Python Qgis cookbook, and a related answer set pythonpath