即使“Pip 中已满足要求”,也未找到 Python 模块

2024-01-12

在 OS X 中编写一些 python,它说我用 pip 安装了几个包“ImportError:没有名为 requests 的模块”

运行 pip install 请求时

> sudo -H pip install requests 
Requirement already satisfied: requests in /usr/local/lib/python2.7/site-packages 
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python2.7/site-packages (from requests) 
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python2.7/site-packages (from requests) 
Requirement already satisfied: urllib3<1.22,>=1.21.1 in /usr/local/lib/python2.7/site-packages (from requests) 
Requirement already satisfied: idna<2.6,>=2.5 in /usr/local/lib/python2.7/site-packages (from requests)

twindb_cloudflare、requests、group、tarutil 和 MySQL DB 上出现错误。我可以在另一个脚本(在同一文件夹中)上运行完全相同的导入,而不会出现错误。


就我而言,我运行的是 Jupyter 附带的 python 版本,它显然将模块安装在与默认位置不同的位置。我通过在 Jupyter 中运行发现了这一点:

import sys
sys.executable

这给了我

'/usr/local/Cellar/jupyterlab/3.0.13/libexec/bin/python3.9'

然后我可以在 Jupyter 中运行以下命令:

!/usr/local/Cellar/jupyterlab/3.0.13/libexec/bin/python3.9 -m pip install scipy matplotlib

然后我就可以导入我的模块:

import scipy.stats
import matplotlib
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

即使“Pip 中已满足要求”,也未找到 Python 模块 的相关文章

随机推荐