2

我的服务器上有两个 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
4

4 回答 4

2

一种方法是:

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

  2. 检查顶行,它应该说

    #!/usr/bin/python

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

于 2012-09-14T19:30:11.503 回答
1

你应该检查这个 SO question

您可能还需要考虑使用虚拟环境virtualenvvirtualenvwrapper管理您的包应使用的 Python 版本。

于 2012-09-15T13:57:47.810 回答
0

如果您想通过下载 .dmg 轻松安装 iPython、SciPy、MatPlotLib 等,可以在这里尝试:

http://www.enthought.com/products/epd_free.php

或者,如果您有学术电子邮件地址:

http://www.enthought.com/products/edudownload.php

于 2012-09-14T19:34:43.527 回答
0

sudo /location/to/python2.7 /path/to/pip install ipython

如果你有最新版本的 pip,你也可以试试sudo pip-2.7 install ipython

于 2012-09-14T19:40:00.507 回答