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
接下来测试一下吧: