“sudo pip"时出错在 AWS ec2 实例上 [英] error when "sudo pip" on an AWS ec2 instance
问题描述
我正在尝试在 aws ec2 实例上运行一个小的 python 代码(它需要 pytz 和其他一些包).当我尝试安装 pytz 时,出现了一些错误:
I am trying to run a small python code (which requries pytz and some other packages) on a aws ec2 instance. When I tried to install pytz, I got some errors:
[ec2-user@ip-172-31-28-178 ~]$ pip install pytz
Collecting pytz
Using cached pytz-2016.7-py2.py3-none-any.whl
Installing collected packages: pytz
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 342, in run
prefix=options.prefix_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, 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 1064, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib64/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/pytz-2016.7.dist-info'
我遵循了本主题的公认答案,但是遇到另一个错误:
I followed the accepted answer of this topic but got another error:
sudo:pip: 命令未找到
后来发现可能是路径设置不对(根据此页面.但我无法按照第二个答案的建议 将 ~/.local/bin 添加到您的路径
.
Then I found out it might be because the path setting is wrong
(according to this page. But I could not manage to Just add ~/.local/bin to your path
as suggested by the second answer.
有人可以告诉我如何将垃圾箱添加到我的路径中吗?我不知道.
Can someone show me how to add the bin to my path? I have no idea.
还有更多信息:
[ec2-user@ip-172-31-28-178 ug]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
[ec2-user@ip-172-31-28-178 ug]$ which pip
/usr/local/bin/pip
[ec2-user@ip-172-31-28-178 ug]$
推荐答案
sudo 的默认设置 (secure_path
) 在 /etc/sudoers
中指定.
The default (secure_path
) for sudo is specified in /etc/sudoers
.
[ec2-user@ip-172-31-28-178 ~]$ sudo grep secure_path /etc/sudoers
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
由于在该路径中未找到 pip
,您将收到未找到错误.运行 sudo
时通过以下方式保留 PATH
:
Since pip
is not found in that path, you are getting the not found error. Preserve your PATH
when running sudo
by:
sudo env "PATH=$PATH" pip install pytz
这篇关于“sudo pip"时出错在 AWS ec2 实例上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!