我尝试通过键入终端来使用pip安装python库openpyxl:
pip install openpyxl
但它没有正确执行。它抛出了一个例外:
Successfully built openpyxl jdcal et-xmlfile
Installing collected packages: jdcal, et-xmlfile, openpyxl
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip/wheel.py", line 323, in clobber
shutil.copyfile(srcfile, destfile)
File "/System/Library/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: '/Library/Python/2.7/site-packages/jdcal.py'
答案 0 :(得分:6)
最好的方法是使用pip install <libname> --user
在您的案例中使用pip install openpyxel --user
这会为您的用户安装软件包,这是安全的。您也可能有权为用户安装软件包。
您遇到的权限错误是一个常见问题。从这里可以看出: pip is not able to install packages correctly: Permission denied error 在这里error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied
使用sudo pip命令被认为不安全,如下所述:What are the risks of running 'sudo pip'?
答案 1 :(得分:3)
您的用户在Python安装文件夹中没有写入权限。
要修复它,请以root身份运行pip:
sudo pip install openpyxl
答案 2 :(得分:0)
您的帐户对此目录没有写入权限?
如果安装目录是系统拥有的目录,则可以 需要以管理员身份登录或&#34; root&#34;帐户。
sudo pip install openpyxl
如果您没有此计算机的管理员权限,则可以 希望选择不同的安装目录,最好是一个 在PYTHON_PATH环境变量中列出。
更简单的方法:更改dir权限:
chmod + a&#39;用户:YOUR_USER_NAME允许add_subdirectory,add_file,delete_child,directory_inherit&#39; /Library/Python/2.7/site-packages
答案 3 :(得分:-1)
将site-packages文件夹的安全设置更改为“完全控制”,并重新运行pip install openpyxl