Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to use QGIS and work with Python out of the console, but I'm having troubles letting the system recognize the paths of some DLLs. Since I couldn't find a good answer on the web, I wonder if I did something wrong. I'm working with Windows 7 64 bit version, using Python 2.7 and QGIS 1.8. In the system environment, I've created and pointed the variable PYTHONPATH to the python directory (which in my case is "C:\Quantum_GIS_Lisboa\apps\qgis\python"). Then I've modified the "Path" variable adding the address where "qgis_core" and "qgis_gui" are found (in my case "C:\Quantum_GIS_Lisboa\apps\qgis\bin"). The instructions I've followed are those of the "PyQGIS Developer Cookbook" ("http://www.qgis.org/pyqgis-cookbook"). It seems the problem relies in recognizing the DLLs, which are in the folder I've pointed to for the variable "Path". Here is the error I have in the Shell when I try to import the module "qgis.core":

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
     import qgis.core
ImportError: DLL load failed: Impossibile trovare il modulo specificato.

Moreover, if I import the sys module and print the path to see what's there, I'm not finding what I expect:

>>> import sys
>>> print sys.path
['C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\ArcGIS\\Python 2.7', 'C:\\Python27\\ArcGIS10.1\\Lib\\idlelib', 'C:\\Quantum_GIS_Lisboa\\apps\\qgis\\python', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\ArcGIS10.1\\DLLs', 'C:\\Python27\\ArcGIS10.1\\lib', 'C:\\Python27\\ArcGIS10.1\\lib\\plat-win', 'C:\\Python27\\ArcGIS10.1\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.1', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\arcpy', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\ArcToolbox\\Scripts', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages\\win32', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages\\Pythonwin']

Hope someone could help me solving this, I'd be really thankful!

I've just tried to copy and paste the whole content of Python27 folder within the main "Quantum GIS Lisboa" folder in the Python27 main folder in my hard drive C, since I saw ArcGIS and Python were working fine like that. Then I tried to launch the IDLE found in "lib/idlelib" ("idle.pyw") from the new folder but this didn't solve the problem. Everything seems to point to the right folders in the system environment. Here is the print of the sys.path after the "reverse" trick:

['C:\\Quantum_GIS_Lisboa\\apps\\qgis\\bin', 'C:\\Quantum_GIS_Lisboa\\apps\\qgis\\python', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages\\win32\\lib',
'C:\\Python27\\ArcGIS10.1\\lib\\site-packages\\win32', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\ArcToolbox\\Scripts', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\arcpy', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin', 'C:\\Python27\\ArcGIS10.1\\lib\\site-packages', 'C:\\Python27\\ArcGIS10.1', 
'C:\\Python27\\ArcGIS10.1\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.1\\lib\\plat-win', 'C:\\Python27\\ArcGIS10.1\\lib', 'C:\\Python27\\ArcGIS10.1\\DLLs', 'C:\\Windows\\system32\\python27.zip', 'C:\\Quantum_GIS_Lisboa\\apps\\qgis\\bin', 'C:\\Quantum_GIS_Lisboa\\apps\\qgis\\python', 'C:\\Python27\\ArcGIS10.1\\Lib\\idlelib', 'C:\\Users\\Umberto\\Desktop']

Traceback (most recent call last):
  File "C:\Users\Umberto\Desktop\set_qgis_01.py", line 5, in <module>
    import qgis.core
ImportError: DLL load failed: Impossibile trovare il modulo specificato.

Am I suppose to point to the Quantum GIS main folder as well as it contains a folder named "lib"?

share|improve this question
    
I'm having the same issue. Has anyone resolved this? I'm running a 64 bit machine with ArcGIS 10.1/Python 2.7 installed at > C:\Python27 and QGIS 1.8.0/Python 2.7 installed at: > C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27 When I try to import osgeo from Pythonwin installed at: > C:\Program Files (x86)\Quantum GIS > Lisboa\apps\Python27\Lib\site-packages I get the following error: > Traceback (most recent call last): File "<interactive input>", line > 1, in <module> File "C:\Program Files (x86)\Quantum GIS > Lisboa\apps\Python27\lib\site-packages\osgeo_init_.py", line 21, in > < –  Mike Mar 21 '13 at 21:30
    
I managed like I show in another question. You'll just have to edit the shell-launcher a bit as to fit your OS.gis.stackexchange.com/questions/53855/… –  umbe1987 Mar 22 '13 at 10:37

1 Answer 1

It looks like you have a similar problem to one I had. Though the specifics of the paths are different I believe that a similar solution can work. See my solution in this post.

What is happening is that it is not just the PYTHONPATH which is read but also the PATH variable. On load QGIS appends the paths of the osgeo binaries to the path, which means they get read last. That means the ArcGIS location is found first and Windows looks no further.

What you don't want to do is muck up your ArcGIS install by playing with the main PATH variable (where there will be a reference to the Arc Python directory). However, if you tell QGIS to reverse the sys.path variable as the first thing it does, it will read the osgeo paths first and ignore the Arc Python instalation. This change is only apparent within the specific Python session (i.e. it has no effect on the actual PATH or PYTHONPATH variables stored on your computer and neither is it permanent, so will be safe as far as ArcGIS is concerned and less dangerous than editting your PATH variable as this could end up breaking Arc with the same problem but the other way around).

Depending on your install, you might want to change my solution to something like (based on what I read in your question):

import sys
sys.path.extend([r"C:\Quantum_GIS_Lisboa\apps\qgis\python",r"C:\Quantum_GIS_Lisboa\apps\qgis\bin"])
sys.path.reverse()

If you have used osgeo4w to install QGIS this will be unnecessary, but you could do it anyway as a belt-and-braces approach - it won't hurt). I suspect you will also need to add the lines at the start of the set_qgis_01.py file (I did mine in the GDALTOOLS.py file because that's where my conflict manifested itself).

share|improve this answer
    
I did it the way you say, having now the path with the two "QGIS" directories at the beginning, but still receiving the same error. I checked the presence of the "qgis_core.dll" file in the "/apps/qgis/bin" folder and don't have a clue why it can't find it (if that is the right thing to search for). Hope you could tell me more. –  umbe1987 Jan 8 '13 at 11:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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