无法sudo python但我可以没有sudo python

时间:2017-04-28 21:25:10

标签: python linux rhel

我正在我的linux机箱上执行一些维护(rhel通过ssh)但是当我去运行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。我很确定我正确安装了它。

编辑:

方法1:

[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

2 个答案:

答案 0 :(得分:2)

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

which python3.6

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

然后你需要做

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

答案 1 :(得分:0)

必须在PATH env变量中未设置python路径: 请尝试按照以下步骤操作:

搜索安装python的路径

ls -lrth /usr/local/bin/python3.5

-rwxr-XR-X。 2 root root 12M Mar 22 15:55 /usr/local/bin/python3.5

1)添加python路径

vim~ / .bash_profile

<强> PATH = $ PATH:$ HOME / bin中:/usr/local/bin/python3.5

导出路径

2)打开新会话(putty或任何其他赞成。)

3) whereis python

4)现在应该可以工作,或者你可以直接执行程序

/usr/local/bin/python3.5 mydemo1.py