Fedora
在 Red Hat Enterprise Linux 6.2 上,如何預設使用 Python 2.7 而不是 Python 2.6?我做了但仍然顯示2.6?
RHEL 6.2 我有 python 2.6,但我需要使用
yum
打包的預設 python 2.7(這樣就不會搞砸,因為它是一個重型工作系統,我只需要 python 2.7 就可以了,不會搞砸)。我做了以下,但我仍然看到
python
版本為 2.6,請問有什麼指針嗎?$ cat /etc/issue Red Hat Enterprise Linux Server release 6.2 (Santiago) Kernel \r on an \m $ python --version Python 2.6.6 $ sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python27.repo >> /etc/yum.repos.d/scl.repo' $ yum search python27 Loaded plugins: amazon-id, rhui-lb, security scl_python27 | 2.9 kB 00:00 scl_python27/primary_db | 38 kB 00:00 ========================================================================= N/S Matched: python27 ========================================================================= python27.i686 : Package that installs python27 python27.x86_64 : Package that installs python27 python27-expat-debuginfo.i686 : Debug information for package python27-expat python27-expat-debuginfo.x86_64 : Debug information for package python27-expat python27-python-coverage-debuginfo.i686 : Debug information for package python27-python-coverage python27-python-coverage-debuginfo.x86_64 : Debug information for package python27-python-coverage python27-python-debuginfo.i686 : Debug information for package python27-python python27-python-debuginfo.x86_64 : Debug information for package python27-python python27-python-markupsafe-debuginfo.i686 : Debug information for package python27-python-markupsafe python27-python-markupsafe-debuginfo.x86_64 : Debug information for package python27-python-markupsafe python27-python-simplejson-debuginfo.i686 : Debug information for package python27-python-simplejson python27-python-simplejson-debuginfo.x86_64 : Debug information for package python27-python-simplejson python27-python-sqlalchemy-debuginfo.i686 : Debug information for package python27-python-sqlalchemy python27-python-sqlalchemy-debuginfo.x86_64 : Debug information for package python27-python-sqlalchemy python27-runtime.i686 : Package that handles python27 Software Collection. python27-runtime.x86_64 : Package that handles python27 Software Collection. python27-babel.noarch : Tools for internationalizing Python applications python27-build.i686 : Package shipping basic build configuration python27-build.x86_64 : Package shipping basic build configuration python27-expat.i686 : An XML parser library python27-expat.x86_64 : An XML parser library python27-expat-devel.i686 : Libraries and header files to develop applications using expat python27-expat-devel.x86_64 : Libraries and header files to develop applications using expat python27-expat-static.i686 : expat XML parser static library python27-expat-static.x86_64 : expat XML parser static library python27-python.i686 : An interpreted, interactive, object-oriented programming language python27-python.x86_64 : An interpreted, interactive, object-oriented programming language python27-python-babel.noarch : Library for internationalizing Python applications python27-python-coverage.i686 : Code coverage testing module for Python python27-python-coverage.x86_64 : Code coverage testing module for Python python27-python-debug.i686 : Debug version of the Python runtime python27-python-debug.x86_64 : Debug version of the Python runtime python27-python-devel.i686 : The libraries and header files needed for Python development python27-python-devel.x86_64 : The libraries and header files needed for Python development python27-python-docutils.noarch : System for processing plaintext documentation python27-python-jinja2.noarch : General purpose template engine python27-python-libs.i686 : Runtime libraries for Python python27-python-libs.x86_64 : Runtime libraries for Python python27-python-markupsafe.i686 : Implements a XML/HTML/XHTML Markup safe string for Python python27-python-markupsafe.x86_64 : Implements a XML/HTML/XHTML Markup safe string for Python python27-python-nose.noarch : Discovery-based unittest extension for Python python27-python-nose-docs.noarch : Nose Documentation python27-python-pygments.noarch : Syntax highlighting engine written in Python python27-python-setuptools.noarch : Easily build and distribute Python packages python27-python-simplejson.i686 : Simple, fast, extensible JSON encoder/decoder for Python python27-python-simplejson.x86_64 : Simple, fast, extensible JSON encoder/decoder for Python python27-python-sphinx.noarch : Python documentation generator python27-python-sphinx-doc.noarch : Documentation for python-sphinx python27-python-sqlalchemy.i686 : Modular and flexible ORM library for python python27-python-sqlalchemy.x86_64 : Modular and flexible ORM library for python python27-python-test.i686 : The test modules from the main python package python27-python-test.x86_64 : The test modules from the main python package python27-python-tools.i686 : A collection of development tools included with Python python27-python-tools.x86_64 : A collection of development tools included with Python python27-python-virtualenv.noarch : Tool to create isolated Python environments python27-python-werkzeug.noarch : The Swiss Army knife of Python web development python27-python-werkzeug-doc.noarch : Documentation for python-werkzeug python27-tkinter.i686 : A graphical user interface for the Python scripting language python27-tkinter.x86_64 : A graphical user interface for the Python scripting language
**編輯:(**替代選項我也嘗試如下):
#!/bin/bash # Install Python 2.7.3 alternatively yum groupinstall "development tools" -y yum install readline-devel openssl-devel gmp-devel ncurses-devel gdbm-devel zlib-devel expat-devel libGL-devel tk tix gcc-c++ libX11-devel glibc-devel bzip2 tar tcl-devel tk-devel pkgconfig tix-devel bzip2-devel sqlite-devel autoconf db4-devel libffi-devel valgrind-devel -y mkdir tmp cd tmp wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar xvfz Python-2.7.3.tgz cd Python-2.7.3 ./configure --prefix=/opt/python2.7 --enable-shared make make altinstall echo "/opt/python2.7/lib" >> /etc/ld.so.conf.d/opt-python2.7.conf ldconfig cd .. cd .. rm -rf tmp [root@ip-10-59-143-73 bin]# pwd /opt/python2.7/bin [root@ip-10-59-143-73 bin]# tree . ├── 2to3 ├── idle ├── pydoc ├── python2.7 ├── python2.7-config └── smtpd.py 0 directories, 6 files [root@ip-10-59-143-73 bin]# ./python2.7 --version Python 2.7.3 [root@ip-10-59-143-73 bin]# python --version Python 2.6.6
我建議不要與系統級 Python 混為一談,而是建議使用
virtualenv
with之類的東西virtualenvwrapper
。這兩個工具一起使建立您自己的 Python + 庫的本地副本變得非常簡單,而不必嘗試將 Python 的系統級安裝保持在需要它的系統級軟體的 OK 狀態。虛擬環境
virtualenv 是一個創建隔離 Python 環境的工具。
它創建了一個具有自己的安裝目錄的環境,它不與其他 virtualenv 環境共享庫(並且可選地也不訪問全域安裝的庫)。
virtualenvwrapper
virtualenvwrapper 是 Ian Bicking 的 virtualenv 工具的一組擴展。這些擴展包括用於創建和刪除虛擬環境以及以其他方式管理您的開發工作流程的包裝器,從而更容易一次處理多個項目,而不會在它們的依賴項中引入衝突。
現在大多數語言都提供這些類型的工具。請參閱我關於此問題的文章,標題為:推薦的用於統計的 Linux 發行版?也適用於其他語言。