3

I am an experienced Python developer, but new to QGIS. I just installed QGIS 2.18.4 and am getting the following error message when I start it.

Couldn't load QGIS utils.
Python support will be disabled.


Traceback (most recent call last):
  File "", line 1, in 
  File "C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python\qgis\utils.py", line 21, in 
    standard_library.install_aliases()
  File "C:\PROGRA~1\QGIS2~1.18\apps\Python27\lib\site-packages\future\standard_library\__init__.py", line 465, in install_aliases
    from future.backports.urllib import request
  File "C:\PROGRA~1\QGIS2~1.18\apps\Python27\lib\site-packages\future\backports\urllib\request.py", line 93, in 
    import hashlib
  File "C:\Python27\Lib\hashlib.py", line 138, in 
    _hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'


Python version:
2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]

QGIS version:
2.18.4 'Las Palmas', 59c1d21

Python path:
['C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python',
u'C:/Users/462974/.qgis2/python',
u'C:/Users/462974/.qgis2/python/plugins',
'C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python/plugins',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\matplotlib-1.3.1-py2.7-win-amd64.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\nose-1.3.3-py2.7.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\tornado-4.0.1-py2.7-win-amd64.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\backports.ssl_match_hostname-3.4.0.2-py2.7.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\certifi-14.05.14-py2.7.egg',

'C:\\Python27\\Lib',
[Rest of my preexisting PYTHONPATH],

'C:\\PROGRA~1\\QGIS2~1.18\\bin\\python27.zip',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\DLLs',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\plat-win',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\lib-tk',
'C:\\PROGRA~1\\QGIS2~1.18\\bin',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\PIL',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\jinja2-2.7.2-py2.7.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\markupsafe-0.23-py2.7-win-amd64.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\pytz-2012j-py2.7.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\win32',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\win32\\lib',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\Pythonwin',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\Shapely-1.2.18-py2.7-win-amd64.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\xlrd-0.9.2-py2.7.egg',
'C:\\PROGRA~1\\QGIS2~1.18\\apps\\Python27\\lib\\site-packages\\xlwt-0.7.5-py2.7.egg']

I already had Python 2.7.12 installed on my machine before installing QGIS; it seems to have come with a prepackaged version of Python, 2.7.5. It appears to be modifying my PYTHONPATH environment variable, adding new directories to it on both sides. The problem is that because it adds C:\Program Files\QGIS 2.18\apps\Python27\lib to the end of the path, after C:\Python27\Lib, it finds the Python 2.7.12 version of hashlib first, which apparently contains code the rest of QGIS' Python distribution can't handle (like the line causing this AttributeError). I scanned the Settings menu and don't see anything about how the PYTHONPATH is constructed. Is it normal for QGIS to not play nice with preexisting Python installations?

1

Python path issues can be frustrating try:

  • Uninstall previous Python versions and old QGIS files
  • ensure you're installing the appropriate version of either 32-bit or 64-bit
  • do a fresh install of QGIS
  • ensure your python path is pointing to the QGIS version
  • double check the ordering of your PYTHONPATH if you still have issues.
  • So do I have just use QGIS' Python installation and effectively downgrade to 2.7.5? I can see the ordering of the PYTHONPATH that would work; I just don't have any control over that order since it is set up by QGIS on startup. – David Pitchford Mar 20 '17 at 16:53
0

QGIS is invoked by starting a qgis.bat file in C:\Program Files\QGIS 2.18\bin, which does the required environment settings to run QGIS in a separate file o4w_env.bat. That file calls C:\Program Files\QGIS 2.18\etc\ini\python-core.bat to change the Python settings:

SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python27
PATH %OSGEO4W_ROOT%\apps\Python27\Scripts;%PATH%

You might be tempted to change that, but your pre-existing Python installation might be missing modules that are needed to run QGIS. So temporarily renaming the folder with the pre-existing python might be the easiest solution.

Or compare both Python installs, and copy missing modules from QGIS to PYTHON27. But keep in mind that the next QGIS version will be running with Python 3, making that work redundant.

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.