Mac使用pip安装python模块异常处理

python版本:2.7
需要用到pip,请自行安装,网上轮子一大车;
周末了想学习一下,没想到上来就遇到了个坎儿;
安装模块的时候报了异常,在网上搜了一气儿,还是记录一下以免再次入坑:

举例:安装pygame模块

sudo pip install pygame
Password
The directory '/Users/macbook/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/macbook/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pygame
  Downloading https://files.pythonhosted.org/packages/20/0d/628d9e6c69a60b097b2af8ce71be06268a30f5865186cb78bc9e74ec6b81/pygame-1.9.3-cp27-cp27m-macosx_10_9_intel.whl (4.8MB)
    100% |████████████████████████████████| 4.8MB 121kB/s 
Installing collected packages: pygame
Could not install packages due to an EnvironmentError: [Errno 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pygame'

没错,就是这个异常,给我打倒了;庆幸的是他就喜欢搞事情,一帆风顺就没意思了
仔细看了异常信息,网上有些说法明显不对,所以可以直接跳过了,直接记录正确做法:

macdeMacBook-Pro:~ macbook$ sudo pip install pygame --user --upgrade --ignore-installed
The directory '/Users/macbook/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/macbook/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pygame
  Downloading https://files.pythonhosted.org/packages/20/0d/628d9e6c69a60b097b2af8ce71be06268a30f5865186cb78bc9e74ec6b81/pygame-1.9.3-cp27-cp27m-macosx_10_9_intel.whl (4.8MB)
    100% |████████████████████████████████| 4.8MB 51kB/s 
Installing collected packages: pygame
Successfully installed pygame-1.9.3

接下来测试一下吧:

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,268评论 25 709
  • 以下摘录自汐的笔记 1 风铃离我家不远,不过就是隔了两排大珊瑚再加上一个“陆地箱”。我对那陆地箱印象特别深:昨天我...
    玫色折纸人阅读 1,544评论 0 1
  • 人生 如此艰难 艰难 时针转动的如此艰难 要等待分针缓慢的挪动60下 要等待那秒针前行3600步 人生 如此的简单...
    不同寻常的帅阅读 1,004评论 0 2
  • 美丽的女人,面色红润! 女人的风情,面若桃花! 那低头的娇羞,不离双颊的一抹绯红!… 平滑紧致的肌肤,如果配上苍白...
    贺力_db90阅读 1,715评论 0 0
  • 就如同那古老的预言一样,世界末日在那一天如期而来。 男人紧紧拉着女人的手拼命跑,躲过了裂开的大地,躲过了坠落的大楼...
    会飞的咖啡阅读 2,924评论 3 2

友情链接更多精彩内容