Mac下使用pip工具安装python模块的方法及注意事项

一. 基于Mac自带的Python2使用pip工具

  • Mac自带Python2,因此,直接在Mac上输入python命令,操作的都是Python2.
  • Mac虽然自带Python2,但是并没有自带对应的pip工具,因此,在使用pip工具之前,需要我们自行安装,命令:
sudo easy_install pip

1.1 使用pip安装python模块

   以安装requests为例,命令:

pip install requests

 如果报错,显示权限不足,则使用命令:

sudo pip install requests

1.2 使用pip工具卸载python模块

以卸载requests为例,命令:

pip uninstall requests

1.3 使用pip查看已安装的模块

以查看requests为例,命令:

pip show --files requests
192:python_tools xxx$ pip show --files requests
Name: requests
Version: 2.18.4
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0
...

1.4 使用pip检查哪些模块需要更新

命令:

pip list --outdated
192:python_tools xxx$ pip list --outdated
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Cache entry deserialization failed, entry ignored
pip (9.0.1) - Latest: 10.0.1 [wheel]
setuptools (28.8.0) - Latest: 39.1.0 [wheel]
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

1.5 使用pip升级模块

以升级requests为例,命令:

pip install --upgrade requests


二. 基于自行安装的Python3使用pip工具

  • 切记,如果你自行安装了Python3,那么就不用再安装pip工具了,Python3的安装包中自带有pip工具;
  • 由于Mac自带Python2,在使用pip工具为Python3安装模块时,必须显式指明pip针对的Python版本,方式如下:

以安装requests为例,命令:

pip3 install requests

与Python2的区别就是,pip命令改为pip3.

扫描二维码关注公众号,回复: 2060041 查看本文章


【特别说明】有任何疑问,请扫描二维码提问:


猜你喜欢

转载自blog.csdn.net/jin_kwok/article/details/80181771
今日推荐