使用非标准 Python 安装
我最近尝试将 CentOS 服务器上的 Python 安装从 2.4.3 升级到 2.7,但它将 2.4.3 列为最新的稳定版本。这是一个问题,因为我有一个Python程序,至少需要2.7才能正常运行。联系支持人员后,他们在单独的目录中安装了 Python 2.7,但我不确定如何访问此版本。每当我尝试运行 python 程序时,它都会使用 2.4.3 版本。我已经考虑过更改 PythonHome 变量,但无法使其正常工作。我可以通过命令行或程序本身来指定我想使用哪个Python版本吗?
I recently attempted to upgrade our Python install on a CentOS server from 2.4.3 to 2.7, however it lists 2.4.3 as the newest stable release. This is a problem because I have a Python program that requires at least 2.7 to run properly. After contacting support they installed Python 2.7 in a separate directory, however I'm not sure how to access this version. Anytime I try to run the python program it uses the 2.4.3 version. I have looked into changing the PythonHome variable, but can't get it to work correctly. Is there anything I can do via the command line or inside the program itself to specify which Python version I want to use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您要求您的支持团队为 Python2.7 构建一个单独的 RPM,并将其安装在单独的位置,并且不与操作系统版本冲突。我之前已经这样做过,在我的 RHEL3、4 和 5 系统上发布一致的 Python 真是太棒了。
接下来,我建议您对 sh-bang(第一行)“#!/bin/env python2.7”使用以下内容,然后确保您的 PATH 包含补充的 Python 安装路径。这样,您的脚本就可以与在工作站上运行时保持一致,并具有自己独特的 python2.7 路径以及生产环境。
I'd suggest you ask your support team to build a separate RPM for Python2.7 and have it installed in a separate location and not conflicting with the OS version. I've done this before it was great to have a consistent Python released across my RHEL3, 4, and 5 systems.
Next, I'd suggest you use the following for your sh-bang (first line) "#!/bin/env python2.7" and then ensure your PATH includes the supplemental Python install path. This way, your script stays the same as you run it on your workstation, with it's own unique path to python2.7, and the production environment as well.
尝试指定 python 可执行文件的完整路径(即
/opt/python27/python
),而不是使用裸露的python
命令。或者,将/opt/python27/
放在PATH
上,早于/usr/local/bin
(其中python
命令可能已经存在,您可以使用which python
检查)。Try specifying the full path to the python executable (i.e.
/opt/python27/python
) rather than using a barepython
command. Alternatively, place/opt/python27/
on yourPATH
earlier than/usr/local/bin
(where thepython
command is presumably already present, you can check withwhich python
).