gpt4 book ai didi

python - 无法使用 sudo python 但我可以在没有 sudo 的情况下使用 python

转载 作者:太空宇宙 更新时间:2023-11-04 09:19:23 25 4
gpt4 key购买 nike

我正在对我的 linux 机器(通过 ssh 的 rhel)进行一些维护,但是当我这样运行 python 脚本时:

asemani$ python3.6 get-pip.py
  File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
File "/tmp/tmp04ft8p5f/pip.zip/pip/__init__.py", line 26, in <module>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
File "/tmp/tmp04ft8p5f/pip.zip/pip/utils/__init__.py", line 27, in <module>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 3031, in _initialize_master_working_set
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 651, in _build_master
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 644, in __init__
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 700, in add_entry
File "/tmp/tmp04ft8p5f/pip.zip/pip/_vendor/pkg_resources/__init__.py", line 2017, in find_on_path
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/site-packages/setuptools-28.8.0.dist-info'

当我尝试使用 sudo 时:

asemani$ sudo python3.6 get-pip.py'
[sudo] password for asemani:
sudo: python3.6: command not found

无法识别 Python?到底是怎么回事?如何在 python3.6 上使用 sudo。我很确定我安装正确。

编辑:

方法一:

[asemani@746c9prda5r asemani]$ sudo -E python3.6 get-pip.py
sudo: python3.6: command not found

方法 2:

[asemani@746c9prda5r asemani]$ sudo /usr/local/bin/python3.6 get-pip.py 
[sudo] password for asemani:
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f0c4b78d908>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/pip/
^COperation cancelled by user

最佳答案

看起来 sudo 正在从环境中丢失您的 PATH,您需要将完整路径传递给 python3.6:

which python3.6

这将为您提供完整路径,例如/opt/bin/python3.6

然后你需要做

sudo /opt/bin/python3.6 get-pip.py

关于python - 无法使用 sudo python 但我可以在没有 sudo 的情况下使用 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43689098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com