1

Import module pip not works:

import pip
Traceback (most recent call last):
  File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'pip'

How can I install for example Pandas module in Python console?

QGIS version: 3.22.1-Białowieża

QGIS code revision: 663dcf8fb9

Qt version: 5.15.2

Python version: 3.9.5

GDAL/OGR version: 3.4.0

PROJ version: 8.2.0

EPSG Registry database version: v10.038 (2021-10-21)

GEOS version: 3.10.0-CAPI-1.16.0

SQLite version: 3.35.2

PDAL version: 2.3.0

PostgreSQL client version: 13.0

SpatiaLite version: 5.0.1

QWT version: 6.1.3

QScintilla2 version: 2.11.5

OS version: Windows 10 Version 2009

2
  • 1
    Pip is the module for installing python packages from CMD/Terminal, not for installing python packages inside python console. Take a look of pip official site, and check your python installation for knowing were to install new modules
    – aldo_tapia
    Commented Dec 7, 2021 at 13:55
  • 1
    You can find also some vital details in this answer: gis.stackexchange.com/a/394695/99589
    – Taras
    Commented Dec 7, 2021 at 14:19

1 Answer 1

0
import platform
import subprocess 
import sys

try:
    import pandas
except ModuleNotFoundError:
    if platform.system() == 'Windows':
        subprocess.call([sys.exec_prefix + '/python', "-m", 'pip', 'install', 'pandas'])
    else:
        subprocess.call(['python3', '-m', 'pip', 'install', 'pandas']) 
    import pandas
1
  • 1
    Does this work for you with QGIS 3.22 on Windows? I get a WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/matplotlib/
    – axel_ande
    Commented Dec 29, 2021 at 5:41

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.