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

Taras
  • 32,823
  • 4
  • 66
  • 137
Wenceslauw
  • 752
  • 5
  • 17
  • 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 Dec 07 '21 at 13:55
  • 1
    You can find also some vital details in this answer: https://gis.stackexchange.com/a/394695/99589 – Taras Dec 07 '21 at 14:19

1 Answers1

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
Wenceslauw
  • 752
  • 5
  • 17
  • 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 Dec 29 '21 at 05:41