使用系统 python osx 的 Pip
我使用 macports 安装了 python26,所以我的系统上正确的 python 是 /opt/local/bin/python
但是,当我这样做时
sudo pip install <packagename>
它给了我
sudo pip install <somepackage>
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/commands/install.py", line 215, in run
import setuptools
ImportError: No module named setuptools
Storing complete log in /Users/navin/.pip/pip.log
所以,我怀疑它正在使用系统 python。我已经通过他们的站点说明安装了分发(其中包含安装工具)。我也通过安装程序安装了 pip。我想,我设法破坏了系统 python 的 setuptools,这就是为什么我现在遇到这个问题:(
我该怎么做才能让 pip 再次工作?
I installed python26 using macports, so the correct python on my system is /opt/local/bin/python
However, when I do
sudo pip install <packagename>
It gives me
sudo pip install <somepackage>
Exception:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/Library/Python/2.6/site-packages/pip-1.0.1-py2.6.egg/pip/commands/install.py", line 215, in run
import setuptools
ImportError: No module named setuptools
Storing complete log in /Users/navin/.pip/pip.log
And so, I suspect that it is using the system python. I've installed distribute (which contains setuptools) via their site instructions. I installed pip via an installer as well. I somehow managed to clobber the setuptools for the system python I think, so that's why I'm having this problem now :(
What do I do to get pip working again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更新:我强烈建议通过从源代码构建来安装 CPython (示例),然后创建要工作的虚拟环境。
总结以上内容,使用 Macports 安装
pip
:会安装名为
py39-pip
的 MacPorts 端口代码>.但是,没有安装
/opt/local/bin/pip
并且port select pip
或port select py27-pip
都失败(与端口选择 python
)。不建议更改另一个发行版的bin
目录中的内容。请注意,
/usr/bin
中的 Python 文件/usr/local/bin
由 MacPython 安装,可从 python.org/opt/local/bin
由 MacPorts 安装。实际的可执行文件可以通过将
ls -ls
应用于上述每个bin
目录中找到的各种与 Python 相关的符号链接来找到。为了确保首先调用 MacPorts 安装的 Python,请将
/opt/local/bin
放在 运行时环境的PATH
早于/usr/bin
和/usr/local/bin
。这可以在文件~/.bash_profile
或文件~/.bashrc
(哪一个取决于您的系统和配置)中完成。例如,最后写入
~/.bashrc
将会产生这种效果(假设目标 shell 将获取文件~/.bashrc
)。正确定义路径后,系统仍然无法在 Macports
bin
目录中找到pip
命令,因为它安装为/opt/local/ bin/pip3.9
。文件/opt/local/bin/pip
不会自动创建。结果,系统继续搜索
PATH
,如果稍后将 MacPython 添加到路径中的某个位置并安装了pip
,则该pip将会出现。
可以通过上面建议的命令来避免这种情况:
UPDATE: I strongly recommend installing CPython by building from source (example), and then creating virtual environments to work in.
Summarizing the above, installing
pip
using Macports:results in an installation of a MacPorts port named
py39-pip
.However, no
/opt/local/bin/pip
is installed andport select pip
orport select py27-pip
both fail (in contrast toport select python
). Changing things in thebin
directory of another distribution is not recommended.Note that Python files in:
/usr/bin
are of the preinstalled Python of macOS/usr/local/bin
are installed by MacPython, available from python.org/opt/local/bin
are installed by MacPorts.The actual executable files can be found by
ls -ls
applied to the various Python-related symbolic links found in each of the abovebin
directories).To ensure that the Python installed by MacPorts is called first, place
/opt/local/bin
within the runtime environment'sPATH
earlier than/usr/bin
and/usr/local/bin
. This can be done in the file~/.bash_profile
or the file~/.bashrc
(which one depends on your system and configuration). For example, writinglast in
~/.bashrc
will have this effect (assuming that the intended shell will source the file~/.bashrc
).After the paths have been appropriately defined, the system still fails to find a
pip
command in the Macportsbin
directory, because it is installed as/opt/local/bin/pip3.9
. The file/opt/local/bin/pip
is not automatically created.As a result, the system continues searching the
PATH
, and if e.g. MacPython is added to the path some place later and haspip
installed, then thatpip
will show up.This can be avoided by the command proposed above:
使用 sudo rm /usr/local/bin/pip 从 /usr/local/bin 中删除 pip。
如果您已使用 macports 安装了 pip,则
which pip
应显示/opt/local/bin/pip
。如果没有,请按照此处的说明重新安装 pip。只要which python
显示/opt/local
安装,它就应该可以工作。如果没有,您将需要编辑PATH
环境变量。Remove pip from /usr/local/bin with
sudo rm /usr/local/bin/pip
.If you have installed pip with macports,
which pip
should then show/opt/local/bin/pip
. If not, install pip again by following the instructions here. As long aswhich python
shows the/opt/local
installation, it should work. If it doesn't, you will need to edit yourPATH
env variable.这是我的设置,让 pip 与 macports 一起使用,并
在安装完成后将 py26-pip 设置为默认 pip,在您可能需要更新路径以包含 pip 安装的 bin 文件后运行以查看 pip 的帮助信息,
将 .bash_profile 编辑为包括类似的东西
Here is my setup to get pip working with macports and set py26-pip as the default pip
after install finishes run to see the help information for pip
after you may need to update your path to include the bin files installed by pip edit .bash_profile to include something like
您应该先将 python 和 pip 安装在 /opt/local/bin/ 中,然后再安装在 /usr/local/bin/ 中。
另外,您应该检查执行
which python
以及 pip 是否安装在 /opt/local/bin/pip 中。You should have the python and pip installed in /opt/local/bin/ prior to those installed in /usr/local/bin/.
Also, you should check to execute
which python
and whether the pip was installed in /opt/local/bin/pip.我发现我需要
ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip
。由于某种原因,即使您尝试激活该版本的 python 或 pip,macports 也没有构建该链接。I found I needed to
ln -s /opt/local/bin/pip-2.7 /opt/local/bin/pip
. For some reason macports didn't built that link, even when you try activating that version of python or pip.