yum install python-setuptools to install easy_install and ansible - errors: AttributeError: other Python Errors

yum install python-setuptools to install easy_install and ansible - errors: AttributeError: other Python Errors

目标:在 RedHat Linux 机器上安装 ansible。

关于这一切如何开始的小概述: 当我的 Linux 机器是 RedHat 5.9 (Tikanga) 时,默认 python 安装的版本是 2.4。我已尽力而为,但由于 Ansible 要求 python >= 2.6,所以无法正常工作。我尝试在 Linux 5.9 版本上安装 2.7.9,但随后事情开始变得非常快。

我确实在 Linux 5.9 上尝试了 2.7.9 python 作为 "make altinstall" 而不是安装,但是在 运行 yum / etc 系统级别时仍然有很多错误命令。

出现的错误很少(有或没有 运行 sudo):

# sudo pip install ansible

Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in ?
    sys.exit(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.4/site-packages/pip-6.0.8-py2.4.egg/pip/__init__.py", line 211
    except PipError as exc:
                     ^
SyntaxError: invalid syntax

# sudo easy_install pip

Searching for pip
Best match: pip 6.0.8
Processing pip-6.0.8-py2.4.egg
pip 6.0.8 is already the active version in easy-install.pth
Installing pip script to /usr/bin
Installing pip2 script to /usr/bin
Installing pip2.4 script to /usr/bin

Using /usr/lib/python2.4/site-packages/pip-6.0.8-py2.4.egg
Processing dependencies for pip

# sudo pip install ansible

Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in ?
    sys.exit(
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.4/site-packages/pip-6.0.8-py2.4.egg/pip/__init__.py", line 211
    except PipError as exc:
                     ^
SyntaxError: invalid syntax

# sudo easy_install ansible

'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 5, in ?
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

等....

终于幸运了,我想,让我们从头开始重新安装 python(所以我 运行 yum erase python, !!! 当心 !!!!),据我所知,这是我 运行 根据我的经验,稍有疏忽的最佳命令。最终结果:我最终在这里创建了一个新产品:http://www.keepcalmandcarryon.com/creator/?shortcode=qCsMlpyc

总之, ...现在,我用较新版本的 RedHat(圣地亚哥 6.6 版)恢复了服务器,这次默认 Python 是: 2.6.6.



当前情况:这就是我现在面临的问题,在安装了 Python 2.6.6 的 RH Linux 5.9 上。

我是 运行: sudo easy_install pip 但是我得到一个错误:

sudo: easy_install: command not found

为了解决以上问题,我现在运行:sudo yum install python-setuptools 它找到了...但向我显示了一些错误。

Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
http://74.125.194.100/yum/x86_64/6Server/%24YUM0/Server/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
http://74.125.194.100/yum/x86_64/supplemental/%24YUM0/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package python-setuptools.noarch 0:0.6.10-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================
 Package                                                   Arch                                           Version                                                Repository                                              Size
==============================================================================================================================================================================================================================
Installing:
 python-setuptools                                         noarch                                         0.6.10-3.el6                                           release.update                                         336 k

Transaction Summary
==============================================================================================================================================================================================================================
Install       1 Package(s)

Total download size: 336 k
Installed size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
http://74.125.194.100/yum/x86_64/6Server/%24YUM0/Server/../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.


Error Downloading Packages:
  python-setuptools-0.6.10-3.el6.noarch: failure: ../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm from release.update: [Errno 256] No more mirrors to try.

-bash-4.1$

任何想法,我怎样才能在我的 Linux 机器 6.6(现在)上获得 easy_install、pip 或 ansible。

谢谢。

运行 以下命令修复所有问题,现在终于安装了 ansible:

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -ivh epel-release-6-8.noarch.rpm

但是在这个阶段,我得到了 Jinja2 的错误...如下所示:ImportError: No module named setuptools

-bash-4.1$ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 40, in <module>
    from setuptools import setup, Extension, Feature
ImportError: No module named setuptools
-bash-4.1$

为了解决上述问题并继续,我 运行 使用以下命令获取 python-setuptools(安装 easy_install)

wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

太好了,现在我的机器上安装了 easy_install。

-bash-4.1$ which easy_install
/usr/bin/easy_install
-bash-4.1$

此时,我想安装ANSIBLE,所以我运行如下:

sudo easy_install pip
sudo pip install ansible

上述 ansible 安装命令输出的最后一行是:

Successfully installed ansible-1.9.0.1 jinja2-2.7.3 markupsafe-0.23 pycrypto-2.6.1

现在,我可以在我的机器上看到 ansible。

-bash-4.1$ which ansible
/usr/bin/ansible
-bash-4.1$

哦,哦...还是有点不对:

-bash-4.1$ ansible --help

Traceback (most recent call last):
  File "/usr/bin/ansible", line 36, in <module>
    from ansible.runner import Runner
  File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 62, in <module>
    from Crypto.Random import atfork
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in <module>
    from Crypto.Random import _UserFriendlyRNG
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
    from Crypto.Random.Fortuna import FortunaAccumulator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
    import FortunaGenerator
  File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in <module>
    from Crypto.Util.number import ceil_shift, exact_log2, exact_div
  File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in <module>
    if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'

-bash-4.1$

我检查过,我的 LD_LIBRARY_PATH 变量已经 set/exported 为:

LD_LIBRARY_PATH=/usr/lib64/:/usr/local/lib64

那还有什么...好吧

运行 以下 steps/commands 解决上述错误并获得实际工作!!!。对于提示,我说是 "y".


echo "y" | sudo pip uninstall pycrypto
echo "y" | sudo yum erase python-crypto
echo "y" | sudo pip uninstall ansible
sudo pip install ansible
## Time to get gmplib 6.0.0(a) etc
wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2
tar -xvjpf gmp-6.0.0a.tar.bz2
## Change to the above extracted folder and run some commands, seems like they'll run forever.
cd gmp-6.0.0
./configure
sudo make  || echo "these few steps will take good amt of time to complete"
sudo make check || echo "hang on and see if all tests passes in the check process"
sudo make install || echo "final shenzi will be done shortly"
sudo make check || echo "really!!!! ????"
which ansible
ansible || ansible --help

!!!最后!!! ----

-bash-4.1$ 哪个 ansible

/usr/bin/ansible

-bash-4.1$ ansible

Usage: ansible <host-pattern> [options]

Options:
  -a MODULE_ARGS, --args=MODULE_ARGS
                        module arguments
  --ask-become-pass     ask for privilege escalation password
  -k, --ask-pass        ask for SSH password
  --ask-su-pass         ask for su password (deprecated, use become)
  -K, --ask-sudo-pass   ask for sudo password (deprecated, use become)
  --ask-vault-pass      ask for vault password
  -B SECONDS, --background=SECONDS
                        run asynchronously, failing after X seconds
                        (default=N/A)
  -b, --become          run operations with become (nopasswd implied)
  --become-method=BECOME_METHOD
                        privilege escalation method to use (default=sudo),
                        valid choices: [ sudo | su | pbrun | pfexec | runas ]
  --become-user=BECOME_USER
                        run operations as this user (default=root)
  -C, --check           don't make any changes; instead, try to predict some
                        of the changes that may occur
  -c CONNECTION, --connection=CONNECTION
                        connection type to use (default=smart)
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
                        set additional variables as key=value or YAML/JSON
  -f FORKS, --forks=FORKS
                        specify number of parallel processes to use
                        (default=5)
  -h, --help            show this help message and exit
  -i INVENTORY, --inventory-file=INVENTORY
                        specify inventory host file
                        (default=/etc/ansible/hosts)
  -l SUBSET, --limit=SUBSET
                        further limit selected hosts to an additional pattern
  --list-hosts          outputs a list of matching hosts; does not execute
                        anything else
  -m MODULE_NAME, --module-name=MODULE_NAME
                        module name to execute (default=command)
  -M MODULE_PATH, --module-path=MODULE_PATH
                        specify path(s) to module library (default=None)
  -o, --one-line        condense output
  -P POLL_INTERVAL, --poll=POLL_INTERVAL
                        set the poll interval if using -B (default=15)
  --private-key=PRIVATE_KEY_FILE
                        use this file to authenticate the connection
  -S, --su              run operations with su (deprecated, use become)
  -R SU_USER, --su-user=SU_USER
                        run operations with su as this user (default=root)
                        (deprecated, use become)
  -s, --sudo            run operations with sudo (nopasswd) (deprecated, use
                        become)
  -U SUDO_USER, --sudo-user=SUDO_USER
                        desired sudo user (default=root) (deprecated, use
                        become)
  -T TIMEOUT, --timeout=TIMEOUT
                        override the SSH timeout in seconds (default=10)
  -t TREE, --tree=TREE  log output to this directory
  -u REMOTE_USER, --user=REMOTE_USER
                        connect as this user (default=c400093)
  --vault-password-file=VAULT_PASSWORD_FILE
                        vault password file
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)
  --version             show program's version number and exit

-bash-4.1$

PS:如果可以,请远离“yum erase python”并为此输入"y",祝你好运。

OP 中显示的大多数错误都是由于版本不匹配造成的。例如。 except: XXX as obj 语法为 introduced in 2.6.

我预计情况会更加复杂,因为您同时安装了 2.4 和 2.6,然后您使用 sudo 来安装东西。

最好以 root 身份打开交互式 shell,在通过 yumpip 安装这么多 python 模块之前正确设置 PATH 和 PYTHONPATH,这样你知道哪些模块安装到哪个前缀。

yum erase python 是愚蠢,因为你可能是通过艰难的方式学到的。

所有这些都是 yum 配置错误:

http://74.125.194.100/yum/x86_64/6Server/%24YUM0/Server/../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.

Error Downloading Packages:
  python-setuptools-0.6.10-3.el6.noarch: failure: ../Packages/python-setuptools-0.6.10-3.el6.noarch.rpm from release.update: [Errno 256] No more mirrors to try.

总的来说ansible installation instructions还是比较靠谱的


--编辑--

The only thing is even when PATH was set to use 2.7.9 python (for which python), and PYTHONPATH / PYTHONHOME were set, Linux 5.9 version was still picking python version 2.4 site packages and the utilities in Linux 5.9 are tightly dependent upon python 2.4. Under /usr/xxx there no folders for LIB for python 2.7.9 at that time until I switched the whole Linux to 6.6 version. And instead of using "make install" for manually installing python, I used "make altinstall" so that both can sit side by side. – Arun Sangal

在 RHEL 5.x 上:/usr/bin/python 将保持 2.4,即使您安装 2.6+(这将转到 /usr/bin/python2.6/usr/bin/python26 或类似的东西。所以默认python 仍然是 2.4(即使安装了 2.6+)

在 RHEL 6.x 上:python 默认情况下未安装 2.4。所以 /usr/bin/python 默认为 2.6。所以默认的python是2.6.

大多数 utilities/scripts 将与 /usr/bin/python 一起执行,因此 你感觉像 'utilities in Linux 5.9 are tightly dependent upon python 2.4'.

通常问题是为 2.6+ 编写的脚本在 RHEL 5.x 上使用 /usr/bin/python 执行,即 python 2.4。 “AFAIK”相反(运行 2.4 脚本与 2.6 解释器)更兼容(不完全)。