朋友们,我在我的 Ubuntu 上下载并安装了 pip。然后我尝试安装 PLY 和 My xml 等包。但是我得到了一串用红色写的句子。
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 731, in install
**kwargs
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 841, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1040, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 343, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 314, in clobber
ensure_dir(destdir)
File "/usr/local/lib/python2.7/dist-packages/pip/utils/__init__.py", line 82, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/ply'
我曾经pip install ply
安装过。
我可以为安装包做什么?
答案1
pip
为每个包创建一个目录/usr/local/lib/python2.7/dist-packages/
(替换2.7
为其他版本)来保存所有必要的文件,因此您需要有足够的权限来创建该目录。
就您而言,您没有足够的权限来创建/usr/local/lib/python2.7/dist-packages/ply
目录,这就是pip
失败的原因。
为了解决这个问题,你可以使用sudo
:
sudo pip install ply
或者更好的是,您可以将自己添加到组中,因为下staff
创建的相关目录归用户和组所有(带有)。pip
/usr/local/lib/
root
staff
setgid
因此你可以这样做:
sudo usermod -a -G staff username
现在注销并重新登录,现在以下应该可以工作了:
pip install ply
答案2
我看到的唯一明显错误是
[Errno 13] Permission denied:
这意味着你忘记以 开头命令sudo
。将命令更改为...
sudo pip install ply