操作系统:Mac OS X 10.7.5 Python版本:2.7.5

我已经从https://pypi.python.org/pypi/setuptools用ez_setup.py安装了setuptools 1.0 然后我从https://pypi.python.org/pypi/pip/1.4.1下载pip.1.4.1 pkg。

在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

谁以前遇到过同样的问题,能给我一些解决方法吗?


当前回答

试着重新安装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

其他回答

按照这个URL的建议,重命名python39。_pth文件。这就解决了问题

https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/#more-5606

ren python39._pth python39._pth.save

我也有同样的问题。 我的解决方案:

对于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

应该简单地解决这个问题。

如果相反,你从python3中缺少pip,那么只需在上面的命令中将python2.7更改为python3。

在macOS 10.15和Homebrew 2.1.6中,我在Python 3.7中得到这个错误。我只需要运行:

python3 -m ensurepip

现在python3 -m 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