我继承了托管服务器上的一个项目,我正在尝试安装 numpy 和 nltk 并将其导入到该项目中。操作系统是centOs 5.10,Web应用程序使用web.py。盒子上安装了两个版本的 python:python 2.4 和 python 3.3。默认指向版本 2.4,“python -V”= python 2.4.3。最终我将升级并使用 python 3.3,转向 Django 等,但目前我仍坚持这个设置。我已经研究了一段时间如何做到这一点。从我的研究中,我读到了如何使用 pip 安装 numpy,然后安装 nltk。在 python2.4 目录中,我可以使用 easy_install 来安装 pip-1.4.1-py2.4.egg。当我尝试使用 pip-2.4 安装任何内容时,我在 pip 文件中收到语法错误。见下文...
$pip-2.4 numpy
File "/home/slrp/bin/pip-2.4", 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 "/home/slrp/lib/python2.4/pip-1.4.1-py2.4.egg/pip/__init__.py", line 10, in ?
from pip.util import get_installed_distributions, get_prog
File "/home/slrp/lib/python2.4/pip-1.4.1-py2.4.egg/pip/util.py", line 17, in ?
from pip.vendor.distlib import version
File "/home/slrp/lib/python2.4/pip-1.4.1-py2.4.egg/pip/vendor/__init__.py", line 8
from __future__ import absolute_import
SyntaxError: from __future__ imports must occur at the beginning of the file
做了一些研究,这个错误似乎来自于我安装了多个 python。这导致我在python2.4中安装virtualenv-1.10.1-py2.4.egg。但是当我尝试运行 virtualenv 时,出现以下错误。
ERROR: this script requires Python 2.6 or greater.
我还尝试使用 python2.4 的简易安装来安装 numpy,但也出现错误。
$easy_install-2.4 numpy
File "/usr/bin/easy_install-2.4", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1670, in main
with_ei_usage(lambda:
File "/usr/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1659, in with_ei_usage
return f()
File "/usr/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1674, 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/command/easy_install.py", line 211, in run
self.easy_install(spec, not self.no_deps)
File "/usr/lib/python2.4/site-packages/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/command/easy_install.py", line 471, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/lib/python2.4/site-packages/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/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/command/easy_install.py", line 919, in run_setup
run_setup(setup_script, args)
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 26, in run_setup
DirectorySandbox(setup_dir).run(
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 63, in run
return func()
File "/usr/lib/python2.4/site-packages/setuptools/sandbox.py", line 29, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 16
from __future__ import division, print_function
SyntaxError: future feature print_function is not defined
再说一遍,我不想升级或更改 python 的版本。在python3.3目录中我能够成功运行virtualenv。我希望这能解决由于多次安装而可能遇到的任何依赖性问题,但事实并非如此。我现在的计划是尝试让 virtualenv 成功运行 python2.4 版本。我希望,如果我能为两个版本的 python 设置虚拟环境,就能解决问题。但正如你所看到的,我无法让 python2.4 中的 virtualenv 成功运行。以下是有关每个 python 目录中内容的更多信息。
[user@server python3.3]$ ls
easy-install.pth nltk-2.0.4-py3.3.egg numpy-1.8.0-py3.3.egg-info PyYAML-3.10-py3.3-linux-i686.egg
ENV numpy pip-1.4.1-py3.3.egg virtualenv-1.10.1-py3.3.egg
[user@server python2.4]$ ls
easy-install.pth git_remote_helpers MySQL_python-1.2.3c1-py2.4-linux-i686.egg pip-1.4.1-py2.4.egg virtualenv-1.10.1-py2.4.egg web
有很多这方面的东西,我已经研究了一段时间。任何帮助是极大的赞赏!谢谢!
答案1
您有多个问题,首先,最近的(版本)库不再支持 python 2.4。
你需要获取 virtualenv 1.7.2 (自 1.8 起不再支持 2.4)
我不确定您是否可以毫无问题地从 2.4 跳转到 3.3,您使用的实际代码(不是第 3 方的代码)将需要进行调整。我至少会考虑使用Python 2.7作为中间步骤。它与 2.4 兼容,并具有许多 3.3 功能以及更兼容(与 3.3)的标准库。
套餐六除了 python 附带的 2to3 工具之外,可能会有帮助。