在对Python进行altinstall时安装distribution



我正在CentOS 5.8上做Python 2.7.3的重新安装,我想要一个提供pip和所有jazz的发行版。然而,我在理解正确的过程中遇到了麻烦,并且分发的设置脚本给了我错误。

当前命令的顺序:(最终将成为我的一个项目使用的设置脚本)

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运行的。它在根shell中工作得很好。我猜脚本不尊重最初在创建子进程或其他东西时使用的UID。

这让我很好奇;这是正确的顺序,当做一个重新安装Python(2.7.3)与分发?或者仅仅是因为分发安装脚本不尊重给定的UID?如果脚本是问题所在,我将如何使用sudo运行它,因为我不希望我的设置需要根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

我在RHEL5.8上有一个非常相似的设置,当我执行

时,我得到了相同的permission denied exception:
$ sudo python2.7 distribute_setup.py
这个问题可以通过使用绝对路径来解决:
$ sudo /usr/local/bin/python2.7 distribute_setup.py

潜在的问题很简单,根帐户的路径中没有/usr/local/bin。


确实,distribute_setup.py试图通过使用sys来重用当前的python解释器来调用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

相关内容

  • 没有找到相关文章

最新更新