python-2.7 - 决定 pip 和 easy_install 使用哪个 python 版本

标签 python-2.7 pip ipython easy-install python-2.4

我的服务器上有两个 python 版本,即 2.4 和 2.7。它运行的是 RHEL 5.8。

我的服务器上已经安装了 pip 和 easy_install。

当我尝试使用 easy_install 或 pip 安装 ipython 时,它给出了一个错误,该错误可能在 python 2.4 中不支持。

我想对 pip 和 easy_install 使用 python 2.7,因为我想使用两者的最新版本。

我应该怎么做才能让 pip 和 easy_install 使用 python 2.7。系统默认安装Python 2.4,我确实想保留它。

Python 2.7 安装在另一个位置。

下面是 easy_install 和 pip 的回溯。两者最终都会出现相同的错误。感谢任何形式的帮助。

画中画

ronak@ronak fun $ sudo pip install ipython
Downloading/unpacking ipython
  Downloading ipython-0.13.zip (6.4Mb): 6.4Mb downloaded
  Running setup.py egg_info for package ipython
    Traceback (most recent call last):
      File "<string>", line 14, in ?
      File "/usr/local/home/ronak/fun/build/ipython/setup.py", line 23
        from __future__ import print_function
    SyntaxError: future feature print_function is not defined
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
  File "<string>", line 14, in ?
  File "/usr/local/home/ronak/fun/build/ipython/setup.py", line 23
    from __future__ import print_function
SyntaxError: future feature print_function is not defined
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/ronak/.pip/pip.log

简单安装:

ronak@ronak $ sudo easy_install ipython
Searching for ipython
Reading http://pypi.python.org/simple/ipython/
Reading http://ipython.scipy.org
Reading http://ipython.scipy.org/dist
Reading http://ipython.scipy.org/dist/0.8.4
Reading http://ipython.scipy.org/dist/0.9.1
Reading http://ipython.org
Reading http://archive.ipython.org/release/0.12.1
Reading https://github.com/ipython/ipython/downloads
Reading http://ipython.scipy.org/dist/old/0.9
Reading http://ipython.scipy.org/dist/0.10
Reading http://archive.ipython.org/release/0.11/
Reading http://archive.ipython.org/release/0.12
Best match: ipython 0.13
Downloading https://github.com/downloads/ipython/ipython/ipython-0.13.zip
Processing ipython-0.13.zip
Running ipython-0.13/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vgPLN2/ipython-0.13/egg-dist-tmp-GHUgsq
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 7, in ?
    sys.exit(
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 1712, in main
    with_ei_usage(lambda:
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
    return f()
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 1716, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib/python2.4/distutils/core.py", line 149, in setup
    dist.run_commands()
  File "/usr/lib/python2.4/distutils/dist.py", line 946, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.4/distutils/dist.py", line 966, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 211, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 446, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 476, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 655, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 930, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/command/easy_install.py", line 919, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/sandbox.py", line 61, in run_setup
    DirectorySandbox(setup_dir).run(
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/sandbox.py", line 105, in run
    return func()
  File "/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/setuptools/sandbox.py", line 64, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'}
  File "setup.py", line 23
    from __future__ import print_function
SyntaxError: future feature print_function is not defined

最佳答案

一种方法是:

  1. 在文本编辑器中打开 pip/easy_install

  2. 检查顶行,应该显示

    #!/usr/bin/python

  3. 将其更改为#!path/to/python2.7

关于python-2.7 - 决定 pip 和 easy_install 使用哪个 python 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12430753/

相关文章:

Python 3.5 pip 9 属性错误 : 'NoneType' object has no attribute 'bytes'

python - 在 Ipython notebook/Jupyter 中,Pandas 没有显示我尝试绘制的图表

macos - 安装 Torch7。 iPython 安装错误 (mac)

file - 如何在 python 中创建文件对象而不使用 open()

python - 如何从这种情况下用 python 删除 <table> 结构?

python - JSON 数据的 POST 与请求的工作方式与curl 不同

python - 将 pdf 文件转换为 base64Binary 的最佳方法是什么?

python - 全新安装时导入 ssl 错误 : 'PROTOCOL_TLS' is not defined

pip - Ansible:在单个 session 上安装多个 Python 包

python - tslearn 包看不到 numpy 安装 python