Edited at

pip install pyopenssl で Permission denied

More than 3 years have passed since last update.

pip install pyopenssl で Permission denied だった際の解決方法

~ pip install pyopenssl

Collecting pyopenssl
Using cached pyOpenSSL-16.1.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages (from pyopenssl)
Collecting cryptography>=1.3.4 (from pyopenssl)
Using cached cryptography-1.5.2-cp27-cp27m-macosx_10_10_intel.whl
Collecting enum34 (from cryptography>=1.3.4->pyopenssl)
Using cached enum34-1.1.6-py2-none-any.whl
Collecting ipaddress (from cryptography>=1.3.4->pyopenssl)
Using cached ipaddress-1.0.17-py2-none-any.whl
Collecting idna>=2.0 (from cryptography>=1.3.4->pyopenssl)
Using cached idna-2.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): setuptools>=11.3 in /usr/local/lib/python2.7/site-packages (from cryptography>=1.3.4->pyopenssl)
Collecting cffi>=1.4.1 (from cryptography>=1.3.4->pyopenssl)
Using cached cffi-1.8.3-cp27-cp27m-macosx_10_10_intel.whl
Collecting pyasn1>=0.1.8 (from cryptography>=1.3.4->pyopenssl)
Using cached pyasn1-0.1.9-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.4.1->cryptography>=1.3.4->pyopenssl)
Installing collected packages: enum34, ipaddress, idna, pycparser, cffi, pyasn1, cryptography, pyopenssl
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 742, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 324, in clobber
shutil.copyfile(srcfile, destfile)
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/enum/__init__.py'

探していくと、 sudo chown -R $USER /lib/python2.7/site-packages/ しちゃえば?

との、方法もあったが、そんなシステムワイドに利用できるフォルダの所有権を簡単に変更するのはバッドな感じがするので、

別の方法を探してたら、下記にたどり着いた。

http://stackoverflow.com/questions/25816674/pip-is-not-able-to-install-packages-correctly-permission-denied-error

pip install pyopenssl --user を 使えとのこと。

念のため確認。

~ pip install --user

--user Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows. (See the Python documentation for site.USER_BASE for full details.)

とのこと。

~ pip install pyopenssl --user

Collecting pyopenssl
Using cached pyOpenSSL-16.1.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages (from pyopenssl)
Collecting cryptography>=1.3.4 (from pyopenssl)
Using cached cryptography-1.5.2-cp27-cp27m-macosx_10_10_intel.whl
Collecting enum34 (from cryptography>=1.3.4->pyopenssl)
Using cached enum34-1.1.6-py2-none-any.whl
Collecting ipaddress (from cryptography>=1.3.4->pyopenssl)
Using cached ipaddress-1.0.17-py2-none-any.whl
Collecting idna>=2.0 (from cryptography>=1.3.4->pyopenssl)
Using cached idna-2.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): setuptools>=11.3 in /usr/local/lib/python2.7/site-packages (from cryptography>=1.3.4->pyopenssl)
Collecting cffi>=1.4.1 (from cryptography>=1.3.4->pyopenssl)
Using cached cffi-1.8.3-cp27-cp27m-macosx_10_10_intel.whl
Collecting pyasn1>=0.1.8 (from cryptography>=1.3.4->pyopenssl)
Using cached pyasn1-0.1.9-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.4.1->cryptography>=1.3.4->pyopenssl)
Installing collected packages: enum34, ipaddress, idna, pycparser, cffi, pyasn1, cryptography, pyopenssl
Successfully installed cffi-1.8.3 cryptography-1.5.2 enum34-1.1.6 idna-2.1 ipaddress-1.0.17 pyasn1-0.1.9 pycparser-2.14 pyopenssl-16.1.0

よしよし。


参考URL

http://stackoverflow.com/questions/7143077/how-can-i-install-packages-in-my-home-folder-with-pip/7143496#7143496

http://stackoverflow.com/questions/25816674/pip-is-not-able-to-install-packages-correctly-permission-denied-error