首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在mac os上使用pip设置库

在mac os上使用pip设置库
EN

Stack Overflow用户
提问于 2020-10-27 12:03:39
回答 1查看 329关注 0票数 0

我需要在python中安装2个包。

代码语言:javascript
复制
pip install requests
pip install websocket-client

youtube上有一段视频,它完美地展示了如何做到这一点-- https://www.youtube.com/watch?v=237dNNQhD3Q --我在windows上尝试过,它运行得非常完美。不过,我需要在mac上安装这些软件包。首先,我按照这里描述的步骤下载pip https://www.geeksforgeeks.org/how-to-install-pip-in-macos/

终端的输出如下:

代码语言:javascript
复制
MacBook-Pro-3:~ GSuh$ curl https://bootstrap.pypa.io/get-pip.py > get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1842k 100 1842k 0 0 7005k 0 —:--:— —:--:— —:--:— 7005k
MacBook-Pro-3:~ GSuh$ sudo python get-pip.py
Password:
Sorry, try again.
Password:
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-pro.. pip 21.0 will remove support for this functionality.
WARNING: The directory '/Users/GSuh/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
|################################| 1.5 MB 2.6 MB/s
Installing collected packages: pip
Successfully installed pip-20.2.4
MacBook-Pro-3:~ GSuh$ sudo pip install requests
WARNING: The directory '/Users/GSuh/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting requests
Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 375 kB/s
Collecting certifi>=2017.4.17
Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
|████████████████████████████████| 156 kB 607 kB/s
Collecting chardet<4,>=3.0.2
Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
|████████████████████████████████| 133 kB 3.6 MB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Downloading urllib3-1.25.11-py2.py3-none-any.whl (127 kB)
|████████████████████████████████| 127 kB 10.4 MB/s
Collecting idna<3,>=2.5
Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
|████████████████████████████████| 58 kB 649 kB/s
Installing collected packages: certifi, chardet, urllib3, idna, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.11
MacBook-Pro-3:~ GSuh$ sudo pip install websocket-client
WARNING: The directory '/Users/GSuh/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting websocket-client
Downloading websocket_client-0.57.0-py2.py3-none-any.whl (200 kB)
|████████████████████████████████| 200 kB 2.4 MB/s
Collecting six
Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six, websocket-client
Successfully installed six-1.15.0 websocket-client-0.57.0
MacBook-Pro-3:~ GSuh$ python

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Aug 24 2019, 18:37:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.
»> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
»>

因此,包被认为是下载,但我不能使用他们。我怎么才能修好它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-27 12:40:42

在Mac上安装python包有点麻烦。幸运的是,虚拟环境可以节省时间,使这一切变得更容易管理。有许多指南可以帮助您设置这一点,但这取决于您的PYTHONPATH是否被正确设置并指向适当的库。

如果你不小心,你就会得到令人生畏的xkcd python环境。这是一个常见的问题,并通过不同的项目(如pipenvpyenvvenv以及其他项目)多次得到解决。

我强烈建议您使用以下工具设置虚拟python env:

  • 自制软件
  • PyEnv
  • Pipenv或virtualenv (可选)

自制软件允许您以某种一致的方式快速安装所需的工具和各种其他依赖项以及适当的配置。

一旦安装了自制版本,您就可以轻松地安装pyenv,这允许您创建多个内部一致的python环境。

从这里,您可以在新的pip虚拟环境中安装PyEnv,并设置一个基本环境。

我更喜欢为每个项目在PyEnviron中使用一个PyEnviron,以防止相互冲突的依赖。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64554068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档