14

While there are tools and methods for QGIS 2 I cannot figure out for 3 I want to install external Python packages such as sqlalchemy etc.

I tried the following things :

  1. Tried to download osgeo4w for QGIS 3.02 as of now there is no advance installation option like it use to be before http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe.

  2. Tried to install setuptools but its not working in the 2nd step. it returns 1. https://www.lutraconsulting.co.uk/blog/2016/03/02/installing-third-party-python-modules-in-qgis-windows/

  3. Went to Python of the C:\Program Files\QGIS 3.0\bin and tried pip but it does not work.

0

4 Answers 4

11

I encounter that problem after installing QGIS 3, too. Therefore, I install Python packages in following way:

  1. Copy python3.dll and python36.dll in (QGIS_PATH)/bin folder to (QGIS_PATH)/apps/Python36/ folder.
  2. Open command prompt as administrator. Go to Python36 folder. cd c:/(QGIS_PATH)/apps/Python36
  3. Install Pyhon packages by python -m pip install package_name.

I use that way, because I couldn't install packages using OSGeo Shell. When I try in OSGeo Shell, Python crashes.


This was one solution that I was using. But OSGeo4W shell with python3 post as @Luke states in comment has exact solution.

0
6

This happened to me as well and I had both QGIS 2.14 and 3.8 installed then. I fixed the pip install issue in my OSGeo4W shell by uninstalling QGIS2.14 from my computer and re-installing QGIS3.8.

If you see the "SNIMissingWarning" in the error message, check out urllib3's documentation here and you'll find that your OSGeo4W shell might be running on an older version of Python (< 2.7.9), which can cause pip install to not function properly when urllib retrieves the package.

Open your OSGeo4W shell and type in below to check the Python version running in your shell.

C:\>python

If it's less than 2.7.9, then you might need to upgrade your QGIS to version 3 and uninstall older versions if any (note that some newer v2 QGIS have Python environments higher than 2.7.9, e.g. QGIS2.18). Once you have an OSGeo4W shell running on a newer version of Python, follow the steps below to install third-party Python packages for QGIS.

C:\>py3_env
C:\>SET PYTHONPATH=
C:\>SET PYTHONHOME=C:\PROGRA~1\QGIS3~1.8\apps\Python37
C:\>PATH 
C:\PROGRA~1\QGIS3~1.8\apps\Python37;C:\PROGRA~1\QGIS3~1.8\apps\Python37\Scripts;{app};C:\PROGRA~1\QGIS3~1.8\apps\Python27\Scripts;C:\PROGRA~1\QGIS3~1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;C:\Program Files\R\R-3.5.1\bin\x64
C:\>python -m pip install package
2

There may be an easier solution. As an example below, the Python module would be 'mypackage'.

  1. Open QGIS
  2. Open the Python Console by clicking on the icon or from the main menu/Plugins.
  3. In the console type import pip
  4. In the console type pip.main(['install','mypackage'])

It worked for me in Windows/QGIS 3.16

0

I still don't know what's wrong, but I found a makeshift solution (described here: QGIS 3.0 migration - unable to install PyPDF2).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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