Python模块即使在PIP中已经满足的“需求”也找不到。
Python说我
在运行PIP安装请求时,
> 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)
我安装了几个包装“ Importerror:no Module not note requests”的软件包,它在TWINDB_CLOUDFLARE,请求,Group,Tarutil和MySQL DB上错误。我可以在另一个脚本(在同一文件夹中)上运行完全相同的导入,而不会出错。 [注意:我在OS X上跑步]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
就我而言,我正在运行Jupyter随附的Python版本,该版本显然在与默认情况下的位置不同。我通过在Jupyter中运行此操作发现了这一点:
这给了我我
,然后我能够在Jupyter中运行以下命令:
然后我能够导入我的模块:
In my case, I was running a python version included with Jupyter, which installs modules in a different place than the default one apparently. I found that out by running this in Jupyter:
which gave me
I was then able to run the following command in Jupyter:
and then I was able to import my modules:
在命令提示符中运行。
如果您有旧版本,请检查系统上安装的版本。
尝试卸载软件包...
尝试安装它:
您还可以测试PIP是否不执行工作。
Run in command prompt.
Check what version you have installed on your system if you have an old version.
Try to uninstall the package...
Try after to install it:
You can also test if pip does not do the job.
我遇到了同样的问题(也在Mac OS中),并通过使用Python3运行Python脚本来解决它:
python3 script.py
在我的情况下,我也使用pip3而不是pip。
i had the same issue(also in MAC OS) and solved it by instead running the python script with python3:
python3 script.py
in my case i was also using pip3 and not pip.
方法1
如果您的系统安装了一个以上的python版本,例如在我的Ubuntu中,默认情况下的Python版本是
Python
和python3
,那么PIP也是具有不同的版本,例如pip
和pip3
。因此,在这种情况下,使用-m
喜欢的特定Python版本访问PIP:或者,
如果您在Linux上,请确保使用
sudo
。方法2
您需要找到安装目录(从Python找到模块的位置)。对于此运行,以下python脚本:
在我的情况下,它返回:
这些是Python用于查找模块的路径,我将复制 dist-packages 路径。因此,现在通过提供以下安装目标路径来运行命令:
在我的情况下,我运行以下命令来解决我的问题:
Method 1
If your system has more than one Python version installed, like in my ubuntu by default Python versions are
python
andpython3
, then pip also has different versions likepip
andpip3
. So in this situation access pip by specific Python version with-m
like:or
Make sure the use of
sudo
if you are on Linux.Method 2
You need to find installation directory (from where Python finds modules). For this run the following Python script:
In my case it returns:
These are the paths that Python uses to find modules, I copy the dist-packages path. So now run the command by providing target path for installation like below:
In my case I run the following command that solve my problem:
我遇到了这个问题,终于找到了解决方案。
使用
“ sudo”到交叉用户安装问题;
和PIP安装-target =/usr/local/python3.7/site-ackages -upgrade {module_name}
有人提到了这一点并为我工作。
I suffered from this problem and finally found the solution.
use
'sudo' to crossoff user installation issue;
and pip install --target=/usr/local/python3.7/site-packages --upgrade {module_name}
someone mentioned this and worked for me.
如果您使用的是Mac,则可能是您使用pip安装了模块(意为python2,但是您使用Python3执行代码,而Python3没有安装了用于Python2的模块)。
Mac将Python版本2设置为默认设置,并且通常不会随附PIP预装或与版本2链接。我建议将其保留。将版本3用于您的个人用例,并将Mac与版本2一起默认。由于您必须自己安装Python3,这意味着您可能还需要检查/安装PIP3。
检查是否已安装Python 3:
检查您是否已安装了PIP3(默认情况下是自Python 3.4以来包含在python 3.4以来):
检查使用PIP3安装的包装:
如果您使用编辑器工具,请确保将其设置为在运行时使用Python3您的文件。
VS代码的示例:
设置VS代码要在右下角使用Python3,在打开.py文件时应该看到:
现在,如果您想将任何模块导入Python,请确保使用PIP3安装它们:
如果您遇到权限问题,则可以考虑使用Sudo权利运行命令:
If you are using a Mac, it could be that you installed the modules with pip (meaning python2, but you execute your code with python3 which does not have the modules you installed for python2).
Mac has python version 2 set as default and usually does not come with pip preinstalled or is linked with version 2. I recommend leaving it that way. Use version 3 for your personal use cases and leave your Mac with version 2 as default. As you have to install python3 yourself, means you might also want to check/install pip3.
Check if you have python 3 installed:
Check if you have pip3 installed (usually included by default since python 3.4):
Check what packages you have installed with pip3:
If you use an editor tool, make sure to set it to use python3 when running your file.
Example for VS Code:
Set VS Code to use Python3 on the bottom right corner, which you should see when having a .py file open:
And now if you want to import any modules into python, make sure to install them with pip3:
If you run into permission issue, you might consider to run the command with sudo rights:
在我的Windows机器上,在不同的位置安装了多个版本的Python。
因此,当我尝试将枕头库作为
pip安装枕头
安装时,它传达了“需求已经满足并显示了另一个目录的路径,其中安装了另一个版本的Python:要解决此错误,我使用
- TARGET
用PIP命令进行以下操作:成功地工作了
On my Windows machine, more than one version of Python were installed in different locations.
Hence when I tried to install Pillow library as
pip install Pillow
, it was giving the message that "Requirement already satisfied and showing the path of another directory where another version of Python installed:To solve this error, I used the
--target
switch with PIP command as below:And it worked successfully
我正在使用Mac,也有同样的问题。我通过升级PIP然后安装相关软件包解决了它。
首先安装最新版本的PIP:
然后安装软件包(例如,numpy):
I am using Mac and I had also same issue. I solved it by upgrading pip then install the relevant package.
Firstly install the latest version of pip:
Then install the package (for example, numpy):
只是为了分享我的发现,也许是一个新手错误,但是在我的情况下,Mariadb是使用“ sudo pip3 install mariaidb”安装的,我试图用'python myscript.py'来运行脚本,但这不起作用。但是当我使用“ Python3 myScript.py”时,我工作了,似乎很重要。
Just to share my findings and perhaps a newbie error, but in my case mariadb was installed using 'sudo pip3 install mariadb' and I tried to run my script with 'python myscript.py' and that didn't work. But I worked when I use 'python3 myscript.py', seems to be that it matters which pyhton you use.
我在安装pymodbustcp的Windows上遇到了这个问题。对我来说,解决方案与这里的另一个类似。我不得不将PowerShell作为管理员运行,然后“ PIP安装PymodBustCP”按预期工作。
I had this problem on Windows installing pyModbusTCP. The solution for me was similar to another here. I had to run PowerShell as admin, then "pip install pyModbusTCP" worked as expected.
如果已安装Python 2,则可以使用以下命令安装Python 2:
现在您可以检查PIP2并可以尝试运行您的程序:
If you have Python 2 installed then you can use the following command to install pip for Python 2:
Now you can check for pip2 and can try to run your program:
我的Raspberry Pi 4未识别
ipython
命令,并且在尝试安装iPython时显示了以下内容:我知道这不是路径问题,因为Ipython是PIP包。
我在
/usr/usr/lib/python3/dist-packages/
下找到了一个ipython
目录,在此目录中,我找到了程序__ main __. py
。运行
__ Main __。py
启动ipython:我将以下别名添加到我的
.bashrc
文件中,以允许我简单地键入ipython
。My Raspberry Pi 4 did not recognise the
ipython
command and the following was displayed when attempting to install iPython:I knew this wasn't a PATH issue as iPython is a pip package.
I found an
IPython
directory under/usr/lib/python3/dist-packages/
and inside this directory I found program__main__.py
.Running
__main__.py
started iPython:I added the following alias to my
.bashrc
file to allow me to simply typeipython
.不确定它是否相关,但是我遇到了类似的问题,直到我意识到自己正在尝试
import request
,但是模块名称是请求
Not sure if it is relevant, but I was having a similar issue until I realized I was trying to
import request
, but the module name isrequests
这是一个线解决方案,例如魔术
Here is one line solution that works like magic
也许这不是您要寻找的解决方案,但就我而言,我在Pycharm中有一个需要PIP库的项目,因此我运行了以下命令:
在项目终端中,它为我提供了该项目所需的库。
Maybe it's not the required solution you were looking for but in my case, I had a project in pycharm that requires PIP library so I ran the following command:
in the project terminal and it got me the library required for the project.

为了它的价值,我在虚拟环境(VENV)中运行了它,它为我解决了
For what it's worth, I've ran it in a virtual environment (venv) and it solved it for me
我遇到了这个问题,这是由于Python从Microsoft Store和Python的安装程序中安装而引起的。
我通过在Windows中的“添加或删除程序”选项卡中卸载Microsoft Store版本来修复它。
I had this problem, and it was caused by having python installed both from the Microsoft store and python's installer.
I fixed it by uninstalling the Microsoft store version in "Add or remove programs" tab in windows.
我也有类似的问题,但是就我而言,上面的答案都没有。 原因可能是Windows 11。
其背后的 Enmhs.png“ alt =”在此处输入图像描述“>
尽管“列出”和“需求已经满足”,但闲置根本无法加载库。
我以相同的方式重复了安装过程
,并开始工作!
我相信合理的方法可以是在网络上广泛讨论的标准文件夹中的Python库以及在您是Windows 11用户的情况下所显示的目录中广泛讨论的。
I had a similar problem, but in my case, none of the answers above worked. The reason behind it is probably Windows 11.
Despite "listed" and "requirement already satisfied" the IDLE couldn't load the library at all.
I've repeated the installation process in the same manner for the other directory
and it started working!
I believe the reasonable way could be the installation of a Python library both in the standard folder discussed widely on the web as well as in the directory shown here in the situation when you are a Windows 11 user.