8

I would like to install the Python library in QGIS, but I have no administrator rights. Unfortunately, each solution found refers to the simplest installation via osGeo4W, which requires running as an administrator:

https://www.youtube.com/watch?v=TPMHhgR-r7E&ab_channel=GEO2004 https://www.youtube.com/watch?v=94W51WuDKzA&ab_channel=UmarYusufhttps://landscapearchaeology.org/2018/installing-python-packages-in-qgis-3-for-windows/

Even if I choose the other option by typing python code in the console like:

 import subprocess
 subprocess.check_call(['python', '-m', 'pip', 'install', 'openpyxl'])

Installing 3rd party python libraries for QGIS on Windows

it will still throw the

Error13: Permission denied

With respect to this situation, I am wondering about the completely manual way of providing the Python library to the QGIS root folder, for instance via simply copying the files from other root directories (i.e. from IDLE Python, where I could install everything without the problems).

Is there any way, which would allow w me to expand the Python library in QGIS without admin rights?

UPDATE:

As per the hint below:

https://www.geeksforgeeks.org/how-to-install-openpyxl-in-python-on-windows/

I've entered this link and followed the steps, but it looks like it's still not valid for QGIS. I've chosen the Folium library as an example. The installation has proceeded very well, although it's still not recognized in PyQGIS.

enter image description here

UPDATE II:

Unfortunately none of the hints below work.

Regarding the first one, the situation looks like this:

enter image description here

The second one presents below:

enter image description here

Maybe I have different path or something?

8
  • Does it work if you add '--user'? Commented Mar 23, 2023 at 15:19
  • You can use source code of the library as part of your python plugin
    – RainForest
    Commented Mar 23, 2023 at 15:42
  • How to find the code like this?
    – Geographos
    Commented Mar 23, 2023 at 15:56
  • geeksforgeeks.org/how-to-install-openpyxl-in-python-on-windows - the second method
    – RainForest
    Commented Mar 23, 2023 at 16:06
  • It works fine, but only in Windows-wide environments, and not particularly for QGIS. I will update the question and explain.
    – Geographos
    Commented Mar 23, 2023 at 16:12

2 Answers 2

11

Since you don't have admin privileges, when you install a package using QGIS Python Console/Editor as follows, it is installed to C:\Users\user\AppData\Roaming folder.

import subprocess
subprocess.check_call(['python', '-m', 'pip', 'install', 'folium'])

enter image description here

Therefore, if you add this folder to the path in your script, you can import the package.

import sys
sys.path.append(r"C:\Users\user\AppData\Roaming\Python\Python39\site-packages")

import folium

enter image description here

5
  • Updated my question, as it's still not resolved. Maybe my path is different? I've downloaded the folium library from pypi and stored in this path manually, but QGIS cannot see it either.
    – Geographos
    Commented Mar 27, 2023 at 9:59
  • I don't know. The code worked when I tried using a restricted user account. Did you manage to install it using OSGeo Shell? Commented Mar 27, 2023 at 10:12
  • Unfortunately not. Anyway, I can accept your answer, because I guess there's something wrong with my laptop/path/firewall. I don't know. At least I know the path, from which QGIS takes the libraries. I will fiddle with it more. Thank you very much :)
    – Geographos
    Commented Mar 27, 2023 at 10:22
  • I prefer that you do not accept the answer. The problem may be different and someone else can provide a solution. Commented Mar 27, 2023 at 10:24
  • OK. I tried something and I think I found a workaround for it and will paste the answer soon.
    – Geographos
    Commented Mar 27, 2023 at 10:34
4

Thanks to the earlier answer, I found another workaround for the issue in the case, when you might have a situation like mine (read Update II).

The steps are:

  1. Download your Python library from the pypi.org website

    enter image description here

  2. Convert files optionally to .zip extension, i.e. by using the https://cloudconvert.com/gz-to-zip

  3. Copy the .zip content to the following directory:

    C:\Users\user\AppData\Roaming\Python\Python39\site-packages
    
  4. Run the following code:

    import sys
    
    sys.path.append(r"C:\Users\user\AppData\Roaming\Python\Python39\site-packages\sgp4-2.21")
    
    import sgp4
    

In the sys.path.append, remember to use the correct folder with your python library as it appears in your zip file.

enter image description here

Then everything should be alright.

Your Answer

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

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