Python模块即使在PIP中已经满足的“需求”也找不到。

发布于 2025-01-31 17:13:54 字数 798 浏览 2 评论 0 原文

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上跑步]

Python is saying several packages I installed with pip "ImportError: no module named requests"

When running pip install requests

> 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)

it's erroring on twindb_cloudflare, requests, group, tarutil, and MySQL DB. I'm able to run the exact same imports on another script (in the same folder) without error. [Note: I'm running on OS X]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

年少掌心 2025-02-07 17:13:54

就我而言,我正在运行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

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:

import sys
sys.executable

which gave me

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

I was then able to run the following command in Jupyter:

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

and then I was able to import my modules:

import scipy.stats
import matplotlib
眼前雾蒙蒙 2025-02-07 17:13:54

在命令提示符中运行。

pip list

如果您有旧版本,请检查系统上安装的版本。

尝试卸载软件包...

pip uninstall requests

尝试安装它:

pip install requests

您还可以测试PIP是否不执行工作。

easy_install requests

Run in command prompt.

pip list

Check what version you have installed on your system if you have an old version.

Try to uninstall the package...

pip uninstall requests

Try after to install it:

pip install requests

You can also test if pip does not do the job.

easy_install requests
云淡月浅 2025-02-07 17:13:54

我遇到了同样的问题(也在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.

邮友 2025-02-07 17:13:54

方法1

如果您的系统安装了一个以上的python版本,例如在我的Ubuntu中,默认情况下的Python版本是 Python python3 ,那么PIP也是具有不同的版本,例如 pip pip3 。因此,在这种情况下,使用 -m 喜欢的特定Python版本访问PIP:

python3 -m pip install package_name

或者,

python -m pip install package_name

如果您在Linux上,请确保使用 sudo

方法2

您需要找到安装目录(从Python找到模块的位置)。对于此运行,以下python脚本:

import sys
print(sys.path)

在我的情况下,它返回:

['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/mudasir_habib/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']

这些是Python用于查找模块的路径,我将复制 dist-packages 路径。因此,现在通过提供以下安装目标路径来运行命令:

python -m pip install package_name -t /your/copied/path

在我的情况下,我运行以下命令来解决我的问题:

sudo python3 -m pip install keras -t /usr/lib/python3/dist-packages

Method 1

If your system has more than one Python version installed, like in my ubuntu by default Python versions are python and python3, then pip also has different versions like pip and pip3. So in this situation access pip by specific Python version with -m like:

python3 -m pip install package_name

or

python -m pip install package_name

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:

import sys
print(sys.path)

In my case it returns:

['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/mudasir_habib/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']

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:

python -m pip install package_name -t /your/copied/path

In my case I run the following command that solve my problem:

sudo python3 -m pip install keras -t /usr/lib/python3/dist-packages
完美的未来在梦里 2025-02-07 17:13:54

我遇到了这个问题,终于找到了解决方案。

默认为用户安装,因为普通站点包装不可写

要求已经满足:django in/usr/lib/python3/dist-packages(2.2.12)

使用
“ sudo”到交叉用户安装问题;

和PIP安装-target =/usr/local/python3.7/site-ackages -upgrade {module_name}

有人提到了这一点并为我工作。

I suffered from this problem and finally found the solution.

Defaulting to user installation because normal site-packages is not writeable

Requirement already satisfied: django in /usr/lib/python3/dist-packages (2.2.12)

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.

聆听风音 2025-02-07 17:13:54

如果您使用的是Mac,则可能是您使用pip安装了模块(意为python2,但是您使用Python3执行代码,而Python3没有安装了用于Python2的模块)。

Mac将Python版本2设置为默认设置,并且通常不会随附PIP预装或与版本2链接。我建议将其保留。将版本3用于您的个人用例,并将Mac与版本2一起默认。由于您必须自己安装Python3,这意味着您可能还需要检查/安装PIP3。

检查是否已安装Python 3:

python3 --version

检查您是否已安装了PIP3(默认情况下是自Python 3.4以来包含在python 3.4以来):

pip3 --version

检查使用PIP3安装的包装:

pip3 list

如果您使用编辑器工具,请确保将其设置为在运行时使用Python3您的文件。

VS代码的示例:
设置VS代码要在右下角使用Python3,在打开.py文件时应该看到:“

现在,如果您想将任何模块导入Python,请确保使用PIP3安装它们:

pip3 install package_name

如果您遇到权限问题,则可以考虑使用Sudo权利运行命令:

sudo pip3 install package_name

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:

python3 --version

Check if you have pip3 installed (usually included by default since python 3.4):

pip3 --version

Check what packages you have installed with pip3:

pip3 list

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: Set Python version

And now if you want to import any modules into python, make sure to install them with pip3:

pip3 install package_name

If you run into permission issue, you might consider to run the command with sudo rights:

sudo pip3 install package_name
遗心遗梦遗幸福 2025-02-07 17:13:54

在我的Windows机器上,在不同的位置安装了多个版本的Python。
因此,当我尝试将枕头库作为 pip安装枕头安装时,它传达了“需求已经满足并显示了另一个目录的路径,其中安装了另一个版本的Python:

“

要解决此错误,我使用 - TARGET 用PIP命令进行以下操作:

python -m pip install Pillow --target="c:\Program Files\Python310\Lib\site-packages"

成功地工作了

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:

enter image description here

To solve this error, I used the --target switch with PIP command as below:

python -m pip install Pillow --target="c:\Program Files\Python310\Lib\site-packages"

And it worked successfully

陌伤ぢ 2025-02-07 17:13:54

我正在使用Mac,也有同样的问题。我通过升级PIP然后安装相关软件包解决了它。

首先安装最新版本的PIP:

pip3 install --upgrade pip

然后安装软件包(例如,numpy):

pip3 install 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:

pip3 install --upgrade pip

Then install the package (for example, numpy):

pip3 install numpy 
旧情勿念 2025-02-07 17:13:54

只是为了分享我的发现,也许是一个新手错误,但是在我的情况下,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.

慕烟庭风 2025-02-07 17:13:54

我在安装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.

べ映画 2025-02-07 17:13:54

如果已安装Python 2,则可以使用以下命令安装Python 2:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py

现在您可以检查PIP2并可以尝试运行您的程序:

pip2 --version

If you have Python 2 installed then you can use the following command to install pip for Python 2:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py

Now you can check for pip2 and can try to run your program:

pip2 --version
草莓酥 2025-02-07 17:13:54

我的Raspberry Pi 4未识别 ipython 命令,并且在尝试安装iPython时显示了以下内容:

me@raspberrypi:~ $ sudo pip3 install ipython
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ipython in /usr/lib/python3/dist-packages (5.8.0)
Requirement already satisfied: pexpect in /usr/lib/python3/dist-packages (from ipython) (4.6.0)

我知道这不是路径问题,因为Ipython是PIP包。

我在/usr/usr/lib/python3/dist-packages/下找到了一个 ipython 目录,在此目录中,我找到了程序 __ main __. py

运行 __ Main __。py 启动ipython:

python3 /usr/lib/python3/dist-packages/IPython/__main__.py

我将以下别名添加到我的 .bashrc 文件中,以允许我简单地键入 ipython

alias ipython='python3 /usr/lib/python3/dist-packages/IPython/__main__.py'

My Raspberry Pi 4 did not recognise the ipython command and the following was displayed when attempting to install iPython:

me@raspberrypi:~ $ sudo pip3 install ipython
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ipython in /usr/lib/python3/dist-packages (5.8.0)
Requirement already satisfied: pexpect in /usr/lib/python3/dist-packages (from ipython) (4.6.0)

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:

python3 /usr/lib/python3/dist-packages/IPython/__main__.py

I added the following alias to my .bashrc file to allow me to simply type ipython.

alias ipython='python3 /usr/lib/python3/dist-packages/IPython/__main__.py'
谈下烟灰 2025-02-07 17:13:54

不确定它是否相关,但是我遇到了类似的问题,直到我意识到自己正在尝试 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 is requests

你是暖光i 2025-02-07 17:13:54

这是一个线解决方案,例如魔术

$(which python) -m pip install package_name

Here is one line solution that works like magic

$(which python) -m pip install package_name
殊姿 2025-02-07 17:13:54

也许这不是您要寻找的解决方案,但就我而言,我在Pycharm中有一个需要PIP库的项目,因此我运行了以下命令:

pip install Pillow

在项目终端中,它为我提供了该项目所需的库。

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:

pip install Pillow

in the project terminal and it got me the library required for the project.
enter image description here

心是晴朗的。 2025-02-07 17:13:54

为了它的价值,我在虚拟环境(VENV)中运行了它,它为我解决了

For what it's worth, I've ran it in a virtual environment (venv) and it solved it for me

尝蛊 2025-02-07 17:13:54

我遇到了这个问题,这是由于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.

复古式 2025-02-07 17:13:54

我也有类似的问题,但是就我而言,上面的答案都没有。 原因可能是Windows 11。

其背后的 Enmhs.png“ alt =”在此处输入图像描述“>

尽管“列出”和“需求已经满足”,但闲置根本无法加载库。

我以相同的方式重复了安装过程

\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0>pip install openpyxl

,并开始工作!

我相信合理的方法可以是在网络上广泛讨论的标准文件夹中的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.

enter image description here

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

\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0>pip install openpyxl

and it started working!

enter image description here

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文