欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python学习之安装第三方模块

程序员文章站 2022-04-06 12:33:26
...

关于Mac下安装时 Python Imaging Library(Pillow) 报错 error: could not create '/Library/Python/2.7/site-packages/olefile': Permission denied的解决方法之一:

报错详情:(格式调整了一下,以便浏览)

$ pip install Pillow 
Collecting Pillow
  Downloading Pillow-4.2.1-cp27-cp27m-
macosx_10_6_intel.macosx_10_9_intel.
macosx_10_9_x86_64.
macosx_10_10_intel.macosx_10_10_x86_64.whl (3.5MB)
    100% |████████████████████████████████| 3.5MB 8.7kB/s 
Collecting olefile (from Pillow)
  Downloading olefile-0.44.zip (74kB)
    100% |████████████████████████████████| 81kB 22kB/s 
Installing collected packages: olefile, Pillow
  Running setup.py install for olefile ... error
    Complete output from command /usr/bin/python -u -c 
"import setuptools, tokenize;
__file__='/private/var/folders/lf/
j4jbbcrn0ql_4d06_zl1y_wm0000gn/T/pip-build-Gcekmp/olefile/setup.py';
f=getattr(tokenize, 'open', open)(__file__);
code=f.read().replace('\r\n', '\n');
f.close();exec(compile(code, __file__, 'exec'))"
 install --record /var/folders/lf/j4jbbcrn0ql_4d06_zl1y_wm0000gn/
T/pip-v1VxKP-record/install-record.txt 
--single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib
    copying OleFileIO_PL.py -> build/lib
    creating build/lib/olefile
    copying olefile/__init__.py -> build/lib/olefile
    copying olefile/olefile.py -> build/lib/olefile
    copying olefile/README.rst -> build/lib/olefile
    copying olefile/README.html -> build/lib/olefile
    copying olefile/LICENSE.txt -> build/lib/olefile
    copying olefile/CONTRIBUTORS.txt -> build/lib/olefile
    running install_lib
    creating /Library/Python/2.7/site-packages/olefile
    error: could not create 
'/Library/Python/2.7/site-packages/olefile': Permission denied
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;
__file__='/private/var/folders/lf/j4jbbcrn0ql_4d06_zl1y_wm0000gn/
T/pip-build-Gcekmp/olefile/setup.py';
f=getattr(tokenize, 'open', open)(__file__);
code=f.read().replace('\r\n', '\n');
f.close();exec(compile(code, __file__, 'exec'))" 
install --record /var/folders/lf/j4jbbcrn0ql_4d06_zl1y_wm0000gn/
T/pip-v1VxKP-record/install-record.txt 
--single-version-externally-managed --compile" 
failed with error code 1 in /private/var/folders/
lf/j4jbbcrn0ql_4d06_zl1y_wm0000gn/T/pip-build-Gcekmp/olefile/


* 上查到相关类似报错,error: could not create '/Library/Python/2.7/site-packages/xlrd': Permission denied,
观察之后发现跟权限有关, 其中这个答案:

Try python setup.py install --user

You shouldn't use sudo as suggested above for two reasons:

You're allowing arbitrary untrusted code off the internet to 
be run as root
Passing the --user flag to python setup.py install will install 
the package to a user-owned directory. 
Your normal non-root user won't be able to
access the files installed by sudo pip or sudo python setup.py

比较赞, 于是:

$ pip install Pillow --user
Collecting Pillow
  Using cached Pillow-4.2.1-cp27-cp27m-macosx_10_6_intel
.macosx_10_9_intel
.macosx_10_9_x86_64.macosx_10_10_intel
.macosx_10_10_x86_64.whl
Collecting olefile (from Pillow)
  Using cached olefile-0.44.zip
Installing collected packages: olefile, Pillow
  Running setup.py install for olefile ... done
Successfully installed Pillow-4.2.1 olefile-0.44

解决问题。