没有名为 certifi 的模块

问题描述 投票:0回答:5

在本地目录上执行 python3 (Python 3.6.8) 脚本时,它运行良好,但在 slurm 中运行 sbatch 作业时,抱怨 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)

添加到Python代码后:

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

或者这个:

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

if module_path not in sys.path:

    sys.path.append(module_path)

出现同样的错误。看来certifi已经安装了。

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

运行Python代码后的错误(Python代码中没有“import certifi”行):

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'

错误(Python 代码中包含“import certifi”行):

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'

问题的解决办法是什么?

python cron slurm modulenotfounderror certifi
5个回答
1
投票

对于 MacOS 上的任何人并且已经运行过

pip install certifi
但仍然无法工作

转到您的

applications
文件夹 > 找到您的
python version
文件夹 -> 双击 python 文件夹中的文件
Install Certificates.command
以安装证书。

等待安装完成

之后,您可以尝试再次使用 requests 包运行代码


0
投票

计算节点上安装的模块是否与本地安装的模块相同?您可能需要咨询 Slurm 管理员。


0
投票

这可能意味着

/usr/local/lib/python3.6/site-packages/
不是 slurm 中的 sbatch 作业可以访问的
PYTHONPATH
环境变量。您可以在运行时添加或附加它:

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

0
投票

如果您登陆此处是因为在 MacOS 中使用

httpie
(或任何其他基于 python 的命令)时遇到问题,请尝试使用 homebrew 安装 python-certifi。这应该作为依赖项的一部分安装,但由于某种原因它并不总是这样做。

brew install python-certifi

-5
投票

pip 安装证书

在 CLI 上尝试此命令

© www.soinside.com 2019 - 2024. All rights reserved.