![](/img/trans.png)
[英]“ImportError: no module named 'requests'” after installing with pip
[英]ImportError: No module named pip
操作系统:Mac OS X 10.7.5 Python 版本:2.7.5
I have installed setuptools 1.0 with ez_setup.py from https://pypi.python.org/pypi/setuptools Then I download pip.1.4.1 pkg from https://pypi.python.org/pypi/pip/1.4.1 .
在 iTerm 中运行 (sudo) python setup.py install
表明
running install
running bdist_egg running egg_info writing requirements to
pip.egg-info/requires.txt writing pip.egg-info/PKG-INFO writing
top-level names to pip.egg-info/top_level.txt writing dependency_links
to pip.egg-info/dependency_links.txt writing entry points to
pip.egg-info/entry_points.txt warning: manifest_maker: standard file
'setup.py' not found
reading manifest file 'pip.egg-info/SOURCES.txt' writing manifest file
'pip.egg-info/SOURCES.txt' installing library code to
build/bdist.macosx-10.6-intel/egg running install_lib warning:
install_lib: 'build/lib' does not exist -- no Python modules to
install
creating build/bdist.macosx-10.6-intel/egg creating
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/PKG-INFO -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pip.egg-info/SOURCES.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/dependency_links.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/entry_points.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/not-zip-safe ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/requires.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/top_level.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO creating
'dist/pip-1.4.1-py2.7.egg' and adding
'build/bdist.macosx-10.6-intel/egg' to it removing
'build/bdist.macosx-10.6-intel/egg' (and everything under it)
Processing pip-1.4.1-py2.7.egg removing
'/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg'
(and everything under it) creating
/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg
Extracting pip-1.4.1-py2.7.egg to
/Users/dl/Library/Python/2.7/lib/python/site-packages pip 1.4.1 is
already the active version in easy-install.pth Installing pip script
to /Users/dl/Library/Python/2.7/bin Installing pip-2.7 script to
/Users/dl/Library/Python/2.7/bin
Installed
/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg
Processing dependencies for pip==1.4.1 Finished processing
dependencies for pip==1.4.1
然后我输入pip install
,错误信息显示如下
Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/2.7/bin/pip", line 9,
in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')() File "build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 357, in
load_entry_point File
"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 2394, in
load_entry_point File
"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 2108, in
load ImportError: No module named pip
以前遇到过同样问题的任何人都可以给我一些解决方法吗?
我有同样的问题。 我的解决方案:
对于 Python 3
sudo apt-get install python3-pip
对于 Python 2
sudo apt-get install python-pip
在 Mac 上使用brew是更好的选择,因为apt-get不可用。 命令:
brew install python
如果您在机器上安装了 python2 和 python3
python2.7 -m ensurepip --default-pip
应该可以解决问题。
相反,如果您缺少 python 3 中的 pip,那么只需在上面的命令中将python2.7
更改为python3
。
使用 macOS 10.15 和 Homebrew 2.1.6,我在使用 Python 3.7 时遇到此错误。 我只需要运行:
python3 -m ensurepip
现在python3 -m pip
对我python3 -m pip
。
安装ez_setup 后,您应该可以使用easy_install
。 要安装pip
只需执行以下操作:
easy_install pip
尝试通过 Python 安装pip
:
请前往: https : //pip.pypa.io/en/stable/installing/
并下载get-pip.py
,然后运行:
(sudo) python get-pip.py
在某种 Linux 上,例如基于 Debian 的发行版,您可能需要考虑先更新“ apt-get ”,以防您通过它安装 python-pip。
sudo apt-get update
这可能有助于 apt-get 更新其索引并找到 python-pip 包。 在此之后,您可能会像这样安装 pip-
sudo apt-get install python-pip (Python2)
sudo apt-get install python3-pip (Python3)
跑步
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
然后在您下载的文件夹中运行以下命令:get-pip.py
python get-pip.py
我在尝试安装 nova 客户端时遇到了同样的问题。
spencers-macbook-pro:python-novaclient root# python setup.py install
running install
/usr/bin/python: No module named pip
error: /usr/bin/python -m pip.__init__ install 'pbr>=0.5.21,<1.0' 'iso8601>=0.1.4' 'PrettyTable>=0.6,<0.8' 'requests>=1.1' 'simplejson>=2.0.9' 'six' 'Babel>=0.9.6' returned 1
我使用自制软件,所以我用sudo easy_install pip
解决了这个问题
spencers-macbook-pro:python-novaclient root# brew search pip
aespipe brew-pip lesspipe pipebench pipemeter spiped pipeviewer
If you meant "pip" precisely:
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
sudo easy_install pip
spencers-macbook-pro:python-novaclient root# sudo easy_install pip
如果您使用 macports,命令应该类似。
我认为以上这些答案都不能解决您的问题。
我也有一次被这个问题搞糊涂了。 您应该按照官方指南pip 安装手动安装pip
(目前涉及运行单个get-pip.py
Python 脚本)
之后,只需sudo pip install Django
。 错误将消失。
我从这里下载了pip
二进制文件,它解决了这个问题。
我知道这个线程很旧,但我只是在 OS X 上为自己解决了与这里描述的不同的问题。
基本上我通过 brew 重新安装了 Python 2.7,它带有 pip。
如果还没有安装 Xcode:
xcode-select –install
按照此处所述安装 Brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后通过 Brew 安装 Python:
brew install python
你已经完成了。 就我而言,我只需要安装 pyserial。
pip install pyserial
我在 MacOS Big Sur 上使用 Python 3.8.6 遇到了同样的错误。
无论我使用pip
还是pip3
我都会收到这个错误:
File "/Users/marcelloromani/dev/<repository>/venv/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
原来我的 virtualenv 已经过时了。 这为我解决了问题:
$ deactivate
$ rm -rf venv
$ virtualenv venv
$ . venv/bin/activate
$ pip install -r src/requirements.txt
在终端试试这个:
ls -lA /usr/local/bin | grep pip
就我而言,我得到:
-rwxr-xr-x 1 root root 284 Сен 13 16:20 pip
-rwxr-xr-x 1 root root 204 Окт 27 16:37 pip2
-rwxr-xr-x 1 root root 204 Окт 27 16:37 pip2.7
-rwxr-xr-x 1 root root 292 Сен 13 16:20 pip-3.4
所以 pip2 || pip2.7 在我的情况下工作,和 pip
下载:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
然后安装pip:
py get-pip.py
然后安装biopython:
py -m pip install biopython
我希望它会有用
我在使用命令创建新的 Python 3 虚拟环境时遇到了问题ModuleNotFoundError: No module named 'pip'
python3 -m venv ~/venv/ontology ## << note: "python3" (problematic)
这是经常建议的命令(此处,其他地方)。 当我进入那个 venv 时,找不到 pip。
在此期间,自从第一次使用该命令创建 Python 虚拟环境以来,我的系统 Python 已从 Python 3.7.4 升级(Arch Linux 系统更新)到 Python 3.9.2。
解决方法是使用命令
python -m venv <your_venv> ## e.g. python -m ~/venv/ontology
当我这样做时( python -m ...
不是python3 -m ...
),venv 现在包含pip
...
要在该 venv 中升级pip
,请使用
<your_venv_path>/bin/python -m pip install --upgrade pip
## e.g.
## /home/victoria/venv/ontology/bin/python -m pip install --upgrade pip
如果你在 ubuntu 中得到“No module named pip”,试试这个。
$python3 -m pip --version
/usr/bin/python3: No module named pip
$sudo apt-get install python3-pip
它对我有用。
安装成功后使用验证
$python3 -m pip --version
升级到最新的 pip 版本
$python3 -m pip install --upgrade pip
我通过将 PYTHONPATH 设置为站点包位置解决了 Linux 上的类似错误。 这是在运行python get-pip.py --prefix /home/chet/pip
。
[chet@rhel1 ~]$ ~/pip/bin/pip -V
Traceback (most recent call last):
File "/home/chet/pip/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
[chet@rhel1 ~]$ export PYTHONPATH=/home/chet/pip/lib/python2.6/site-packages
[chet@rhel1 ~]$ ~/pip/bin/pip -V
pip 9.0.1 from /home/chet/pip/lib/python2.6/site-packages (python 2.6)
我的 py 版本是 3.7.3,这个 cmd 有效
python3.7 -m pip install requests
请求库 - 用于从 Web API 检索数据。
这将运行 pip 模块并要求它在 PyPI.org(Python 包索引)上找到 requests 库并将其安装在您的本地系统中,以便您可以导入
下面针对 Linux 进行了测试:您可以直接从https://pypi.org/simple/pip/ untar 下载 pip 并直接与您最新的 python 一起使用。
tar -xvf pip-0.2.tar.gz
cd pip-0.2
检查内容。
anant$ ls
docs pip.egg-info pip-log.txt pip.py PKG-INFO regen-docs scripts setup.cfg setup.py tests
直接执行:
anant$ python pip.py --help
Usage: pip.py COMMAND [OPTIONS]
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-E DIR, --environment=DIR
virtualenv environment to run pip in (either give the
interpreter or the environment base directory)
-v, --verbose Give more output
-q, --quiet Give less output
--log=FILENAME Log file where a complete (maximum verbosity) record
will be kept
--proxy=PROXY Specify a proxy in the form
user:passwd@proxy.server:port. Note that the
user:password@ is optional and required only if you
are behind an authenticated proxy. If you provide
user@proxy.server:port then you will be prompted for a
password.
--timeout=SECONDS Set the socket timeout (default 15 seconds)
以下是使用 MacPorts 升级到 Python 3 的最小指令集:
sudo port install py37-pip
sudo port select --set pip pip37
sudo port select --set pip3 pip37
sudo pip install numpy, scipy, matplotlib
我运行了一些旧代码,这次升级后它又可以工作了。
按照此 URL 上的建议重命名 python39._pth 文件。 这解决了问题
ren python39._pth python39._pth.save
我只需要用pip3
替换pip
所以我最终运行了如下命令: pip3 install matplotlib
我在从requirements.txt
文件安装依赖python3.8
时遇到了类似的问题, virtualenv
有python3.8
。 我设法通过激活virtualenv
然后运行命令python -m pip install -r requirements.txt
让它工作,它工作了。
尝试重新安装 pip 使用 curl 命令下载 get-pip.py 文件:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
如果 curl 不起作用,请打开此链接: get-pip.py
在您的目录中创建一个 get-pip.py 文件,复制此链接中的代码并将其放入 get-pip.py 文件中,并将该文件保存在同一目录中。 然后运行命令
python get-pip.py
我使用的是 Debian,但此解决方案也适用于 Ubuntu。
python -m pip --version
# For Python 2 sudo apt install python-pip # For Python 3 sudo apt install python3-venv python3-pip
get-pip.py
脚本,因为在文档页面中提到了以下内容。如果您使用由操作系统或其他包管理器管理的 Python 安装,请务必小心。 get-pip.py 不与这些工具协调,并且可能会使您的系统处于不一致的状态。
运行 sudo apt-get install pip 并重试这个修复了我的问题的过程
对于 Windows:
python -m ensurepip
激活您的 env ex 后:venv
(venv) PS D:\your path> d:\your path\venv\scripts\python.exe -m pip install --upgrade pip
结果样本:
收集点子
使用缓存的 pip-21.3-py3-none-any.whl (1.7 MB)
安装收集的包:pip
尝试卸载:pip
Found existing installation: pip 20.1.1
Uninstalling pip-20.1.1:
Successfully uninstalled pip-20.1.1
成功安装 pip-21.3
Windows中PIP升级步骤(一)首先,在Windows搜索框中输入Command Prompt
(2) 接下来,打开命令提示符,您将看到以下屏幕,显示您的用户名(为避免任何权限问题,您可以考虑以管理员身份运行命令提示符):
C:\\Users\\Ron> (3) 在命令提示符中,键入“cd\\”以确保您的起点只有驱动器名称:
C:\\用户\\Ron>cd
(4) 按回车,你会看到驱动器名称 C:>
C:> (5) 找到你的 Python 应用程序路径,也就是你最初安装 Python 的文件夹。
以下是 Python 应用程序路径的示例:
C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39
(6) 检索到 Python 应用程序路径后,在命令提示符中键入以下命令:
“cd”后跟您的 Python 应用程序路径
对于我们的示例:
C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39 (7) 按回车,你会看到:
C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39> (8) 要升级 PIP,请键入\/复制此命令,然后按 Enter:
python -m pip install --upgrade pip 这是命令在命令提示符中的样子:
C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39>python -m pip install ––upgrade pip (9) 你会注意到会安装最新版本的 PIP:
成功安装 pip-21.1.1 在 Windows 中检查 PIP 版本的步骤 要随时检查 PIP 的版本,您需要使用 Python 脚本路径,而不是 Python 应用程序路径。
(1) 首先,键入“cd\\”以确保您的起点只有驱动器名称:
C:\\用户\\Ron>cd
(2) 然后,找到您的 Python 脚本路径。 Scripts 文件夹应位于 Python 应用程序路径中。
对于我们的示例,Python 脚本路径是:
C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts
(3) 键入“cd”,后跟 Python Scripts 路径(然后按 Enter):
C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts (4) 最后输入以下命令查看PIP的版本:
pip --version 对于我们的示例:
C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts>pip ––version (5) 回车,你会看到PIP版本:
pip 21.1.1 现在,如果您想恢复到以前的 PIP 版本怎么办?
您可以按照以下步骤轻松降级到以前版本的 PIP。
python -m ensurepip --user
如果你的 mac 不在 big sur 以上
你安装了 py 3 -
我这样做了,我现在没有问题
我猜想回到旧版 2.7。
我在win11上遇到了同样的错误,所以主要问题是在没有管理员权限的情况下执行pip命令,所以用管理员权限打开你的终端,然后再次执行pip命令。 希望能帮助到你,
对于 Windows:
如果下载 Python 时pip
不可用:运行命令
python get-pip.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.