1

I want to use this script here Ortho Projection produces artifacts unfortunatley I cannot download the PlugIn since I work in QGIS 2.8.

It says, set the PYTHONPATH. I do not quite understand what that means... It sets the path to a folder, where python is supposed to look for something. So far, so good. But, is that something which I have to change permanently.

If I change it permanently, will my other site-packages still work?

Where do I have to change it?

In python when starting it from the console or in the console itself?

In my profile?

I am working on Mac 10.10

What I did so far is opening my .bash-profile and I added this peace PYTHONPATH=$PYTHONPATH:/Users/.../.../Python_Toolbox/qgis

As far as I understood it, that should be permanently, right?

But when I go into QGIS into the console and try to import XX it does not find it.

1

Found this in the PyQGIS Developer Cookbook, hope it helps

Running Custom Applications

You will need to tell your system where to search for QGIS libraries and appropriate Python modules if they are not in a well-known location — otherwise Python will complain:

>>> import qgis.core
ImportError: No module named qgis.core

This can be fixed by setting the PYTHONPATH environment variable. In the following commands, qgispath should be replaced with your actual QGIS installation path:

on Linux: export PYTHONPATH=/qgispath/share/qgis/python
on Windows: set PYTHONPATH=c:\qgispath\python

The path to the PyQGIS modules is now known, however they depend on qgis_core and qgis_gui libraries (the Python modules serve only as wrappers). Path to these libraries is typically unknown for the operating system, so you get an import error again (the message might vary depending on the system):

>>> import qgis.core
ImportError: libqgis_core.so.1.5.0: cannot open shared object file: No such file or directory

Fix this by adding the directories where the QGIS libraries reside to search path of the dynamic linker:

on Linux: export LD_LIBRARY_PATH=/qgispath/lib
on Windows: set PATH=C:\qgispath;%PATH%
  • Thanks a lot for your effort. What my concern is - When I replace all these PATH's or add them, will that make my python for other scripts useless? I use it in the consel etc. to run selfwritten script which need libraries as well (in the site package folder). Will python still find them? – Stophface Mar 21 '15 at 15:07
  • check this answer out stackoverflow.com/a/3402176/1224046 – geomajor56 Mar 21 '15 at 15:13
  • okay. I will give it a go. I will let you know weather it worked – Stophface Mar 21 '15 at 15:21
  • hey. when I try to import qgis.core I still get the error. I followed your steps though. – Stophface Mar 25 '15 at 16:01
  • please post the result of echo $LD_LIBRARY_PATH and echo $PYTHONPATH – Hugo Roussaffa - GeoDatup Sep 30 '17 at 9:52
0

Under MacOS default path are set like that

export PYTHONPATH=/Applications/Qgis.app/Contents/Resources/python
export LD_LIBRARY_PATH=/Applications/Qgis.app/Contents/Resources/lib

to do it permanently use this commande instead

echo 'export PYTHONPATH=/Applications/Qgis.app/Contents/Resources/python' >> ~/.bash_profile
echo 'export LD_LIBRARY_PATH=/Applications/Qgis.app/Contents/Resources/lib' >> ~/.bash_profile
source ~/.bash_profile

then run python and check it

import qgis.core

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.