我正在使用CentOS 5.8上的Python 2.7.3,我希望发行分配给pip和所有爵士乐。但是我无法理解正确的程序,而分发的设置脚本给了我错误。
命令的当前顺序:(最终将是用于我的项目的设置脚本)
sudo yum groupinstall "Development tools"
sudo yum install {zlib,bzip2,openssl,ncurses}-devel
cd /tmp && mkdir python273 && cd python273
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar -xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/usr/local --enable-shared
make
sudo make altinstall # installs to /usr/local/{bin,lib}
# Fix path to shared lib - http://stackoverflow.com/a/7880519/1076493
echo "/usr/local/lib" | sudo tee -a /etc/ld.so.conf > /dev/null
sudo ldconfig
# Distribute
wget http://python-distribute.org/distribute_setup.py
sudo python2.7 distribute_setup.py
# Done, install whatever interesting packages I want + clean up
sudo pip install virtualenv yolk bpython
rm -rf /tmp/python273
然而,当我尝试运行distribute_setup.py
时,我正在获取“权限被拒绝”,即使它是使用sudo运行的。在root shell中执行它时工作正常。我猜这个脚本不尊重最初在制作子流程时使用的UID。
这让我很奇怪;这是使用发布版本的Python(2.7.3)的正确顺序吗?或者仅仅是分发设置脚本不尊重给定的UID?如果脚本是问题,我将如何使用sudo运行它,因为我不希望我的设置需要root shell?
$ sudo python2.7 distribute_setup.py
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
Extracting in /tmp/tmpE9UJke
Now working in /tmp/tmpE9UJke/distribute-0.6.35
Installing Distribute
Traceback (most recent call last):
File "distribute_setup.py", line 546, in <module>
sys.exit(main())
File "distribute_setup.py", line 543, in main
return _install(tarball, _build_install_args(options))
File "distribute_setup.py", line 87, in _install
if not _python_cmd('setup.py', 'install', *install_args):
File "distribute_setup.py", line 37, in _python_cmd
return subprocess.call(args) == 0
File "/usr/local/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/local/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/local/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
答案 0 :(得分:8)
我在RHEL5.8上有一个非常类似的设置,当我执行时,我得到了相同的权限被拒绝异常:
$ sudo python2.7 distribute_setup.py
通过使用绝对路径来解决问题:
$ sudo /usr/local/bin/python2.7 distribute_setup.py
根本问题只是root帐号中没有/ usr / local / bin。
确实distribute_setup.py
尝试通过重用当前python解释器sys.executable和subprocess.call来调用python子命令,如果你一步一步地尝试它:
$ sudo python2.7 -c "import sys; print sys.executable"
$ sudo /usr/local/bin/python2.7 -c "import sys; print sys.executable"
/usr/local/bin/python2.7
权限被拒绝错误有点误导,但这是由于尝试执行空文件名引起的:
$ python2.7 -c "import subprocess; subprocess.call([''])"
[...]
OSError: [Errno 13] Permission denied