Installing third party modules in Python
If we want to import a third party module in Python and we get en error as below; we need to install that module first. Below example is to import module named "untangle".
>>> import untangle
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import untangle
ModuleNotFoundError: No module named 'untangle'
To install the module:
- Close the current session of IDLE.
- Open command prompt and type "pip install untangle"
c:\Users\xyz>pip install untangle
Note: Sometimes, due to proxy servers in corporate LANs, step 2 fails with below error
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)'))': /simple/untangle/
Could not fetch URL https://pypi.org/simple/untangle/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/untangle/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)'))) - skipping
ERROR: Could not find a version that satisfies the requirement untangle (from versions: none)
ERROR: No matching distribution found for untangle
To solve the SSL error, use below command
c:\Users\xyz>pip install --user --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org untangle
3. Open new session of IDLE and do the import again. It will be successful this time.