No module named certifi

Question:

When executing python3 (Python 3.6.8) script on a local directory, it works well, but when running sbatch job in slurm, complains about certifi.

python3 -m pip install certifi

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: certifi in /usr/local/lib/python3.6/site-packages (2020.12.5)

After adding to the python code this:

import sys
import os
sys.path.append(os.getcwd())

or this:

import sys
import os
module_path = os.path.abspath(os.getcwd())

if module_path not in sys.path:

    sys.path.append(module_path)

the same error occurs. It seems that certifi is installed.

pip show certifi

Name: certifi
Version: 2020.12.5
Summary: Python package for providing Mozilla's CA Bundle.
Home-page: https://certifiio.readthedocs.io/en/latest/
Author: Kenneth Reitz
Author-email: [email protected]
License: MPL-2.0
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by: requests

The error after running python code (without having the line ‘import certifi’ in python code):

Traceback (most recent call last):
  File "/home/username/test/test.py", line 19, in <module>
    from textattack.augmentation import WordNetAugmenter, EmbeddingAugmenter, EasyDataAugmenter, CharSwapAugmenter
  File "/home/username/.local/lib/python3.6/site-packages/textattack/__init__.py", line 12, in <module>
    from . import (
  File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/__init__.py", line 21, in <module>
    from .attack_recipe import AttackRecipe
  File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/attack_recipe.py", line 9, in <module>
    from textattack.shared import Attack
  File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/__init__.py", line 11, in <module>
    from . import utils
  File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/__init__.py", line 1, in <module>
    from .install import *
  File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/install.py", line 9, in <module>
    import requests
  File "/home/username/.local/lib/python3.6/site-packages/requests/__init__.py", line 118, in <module>
    from . import utils
  File "/home/username/.local/lib/python3.6/site-packages/requests/utils.py", line 25, in <module>
    from . import certs
  File "/home/username/.local/lib/python3.6/site-packages/requests/certs.py", line 15, in <module>
    from certifi import where
ModuleNotFoundError: No module named 'certifi'

The error (with having the line ‘import certifi’ in python code):

Traceback (most recent call last):
  File "/home/username/projecttest_LR_attack/LR_attack.py", line 17, in <module>
    import certifi
ModuleNotFoundError: No module named 'certifi'

What could be the solution to the issue?

Asked By: Fusen

||

Answers:

This could mean that /usr/local/lib/python3.6/site-packages/ is not your PYTHONPATH environment variable that sbatch job in slurm has access to. You can either add it or append it during runtime:

import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
Answered By: PApostol

Are the same modules installed on the compute nodes as locally? You may need to check with the Slurm admins.

Answered By: ciaron

pip install certifi

Try this command on the CLI

Answered By: Ramahanisha Gunda

for anyone on MacOS and already ran pip install certifi and still doesn’t work

Go to your applications folder > find your python version folder -> double click on the file Install Certificates.command inside the python folder to install the certificate.

wait for it to complete the installation

After that, you can try running your code with requests package again

Answered By: Linh Nguyen