简体   繁体   English

在 mac 上安装 pip 失败

[英]Install pip on mac failed

So I installed different versions of Pythons on my mac and it seems this is the root of all my problems at the moment.所以我在我的 Mac 上安装了不同版本的 Python,这似乎是我目前所有问题的根源。 I want to import the module named pyperclip in Mueditor but it always says No module named 'pyperclip'我想在 Mueditor 中导入名为 pyperclip 的模块,但它总是说No module named 'pyperclip'

I read a lot of different other threads and tried to sudo /usr/bin/python get-pip.py But I always get /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory Which indicates that it is searching in the wrong directory (not sure with the correct terminology here).我阅读了很多不同的其他线程并尝试sudo /usr/bin/python get-pip.py但我总是得到/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory这表明它在错误的目录中搜索(不确定此处的术语是否正确)。

I installed Python 3.8 with homebrew and everything is updated fine.我用自制软件安装了 Python 3.8,一切都更新得很好。

For context: I started programming with anaconda, deleted it downloaded Python from the official website and am using Mueditor right now while following the tasks in the book 'Automate the boring stuff with Python'.对于上下文:我开始使用 anaconda 进行编程,删除它从官方网站下载 Python 并且现在正在使用 Mueditor,同时遵循“用 Python 自动化无聊的东西”一书中的任务。

I am even considering setting up my OSX again... Help is much appreciated!我什至正在考虑再次设置我的 OSX ......非常感谢帮助!

I read a lot of different other threads and tried to sudo /usr/bin/python get-pip.py But I always get /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory Which indicates that it is searching in the wrong directory (not sure with the correct terminology here).我阅读了很多不同的其他线程并尝试sudo /usr/bin/python get-pip.py但我总是得到/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory这表明它在错误的目录中搜索(不确定此处的术语是否正确)。

I installed Python 3.8 with homebrew and everything is updated fine.我用自制软件安装了 Python 3.8,一切都更新得很好。

  1. You need to download the get-pip.py file and then execute that command referencing that file.您需要下载get-pip.py文件,然后执行引用该文件的命令。
    https://bootstrap.pypa.io/get-pip.py https://bootstrap.pypa.io/get-pip.py

  2. Make sure you are selecting the right Python interpreter.确保您选择了正确的 Python 解释器。 You have multiple installed.你有多个安装。 You can check their versions with /usr/bin/python -V .您可以使用/usr/bin/python -V检查他们的版本。 In your case /usr/bin/python/ is Python 2.7.在您的情况下/usr/bin/python/是 Python 2.7。

  3. Python 3.8 comes with pip installed. Python 3.8 安装了pip Once you figured out the path of your Python3 interpreter you can do: /path/to/your/python3 -m pip install pyperclip .一旦确定了 Python3 解释器的路径,您就可以执行以下操作: /path/to/your/python3 -m pip install pyperclip

Check the Python version:查看 Python 版本:

python --version
python3 --version

Install pip using easy_install on MacOS在 MacOS 上使用 easy_install 安装 pip

easy_install is a Python module bundled with setuptools which gives us the ability to download, build, install and manage Python packages easy_install 是一个与 setuptools 捆绑在一起的 Python 模块,它使我们能够下载、构建、安装和管理 Python 包

sudo easy_install pip

Install pip using get-pip.py on MacOS在 MacOS 上使用 get-pip.py 安装 pip

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

python get-pip.py

or或者

python3 get-pip.py

Install pip with brew on MacOS在 MacOS 上使用 brew 安装 pip

brew install python

If any problems related to the pip usage we will have to relink the python with the following command.如果与 pip 使用相关的任何问题,我们将不得不使用以下命令重新链接 python。

brew unlink python && brew link python
brew unlink python3 && brew link python3

In the end after following any of the above steps, check and verify pip version最后按照上述任一步骤,检查并验证 pip 版本

pip -V

pip3 -V

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM