2016年11月25日 星期五

[ Python 常見問題 ] Installing Python 2.7 on Centos 6.7

Source From Here 
Introduction 
Follow this sequence exactly for centos machine only CentOS 6.7 ships with Python 2.6.6 and depends on that specific version. Be careful not to replace it or bad things will happen. If you need access to a newer version of Python you must compile it yourself and install it side-by-side with the system version. Here are the steps necessary to install Python 2.7.6. Execute all the commands below as root. Either log in as root temporarily or use sudo. 

How-To 

To check centos version: 
# cat /etc/redhat-release
CentOS release 6.7 (Final)

Install development tools: 
In order to compile Python you must first install the development tools: 
# sudo yum groupinstall "Development tools"

You also need a few extra libs installed before compiling Python or else you will run into problems later when trying to install various packages: 
# sudo yum install zlib-devel
# sudo yum install bzip2-devel
# sudo yum install openssl-devel
# sudo yum install ncurses-devel
# sudo yum install sqlite-devel

Then download, compile and install Python. The –no-check-certificate is optional: 
# cd /opt
# sudo wget --no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
# sudo tar xf Python-2.7.6.tar.xz
# cd Python-2.7.6
# sudo ./configure --prefix=/usr/local
# sudo make && sudo make altinstall

It is important to use altinstall instead of install, otherwise you will end up with two different versions of Python in the filesystem both named python. (Depending on your version of wget, you may need to add the –no-check-certificateoption to the wget command line.) After running the commands above your newly installed Python 2.7.6 interpreter will be available as /usr/local/bin/python2.7 and the system version of Python 2.6.6 will be available as /usr/bin/pythonand /usr/bin/python2.6

Add that some python libraries (such as Theano) require a dynamic library: 
# sudo ./configure –enable-shared –prefix=/usr/local LDFLAGS="-Wl,–rpath=/usr/local/lib"

If you get this error: 
onfigure: WARNING: you should use –build, –host, –target
configure: WARNING: invalid host type: –enable-shared
configure: error: invalid variable name: `–prefix’

# sudo ./configure --enable-shared \
--prefix=/usr/local \
LDFLAGS="-R /usr/local/lib"

Check with: 
# ls -ltr /usr/bin/python*
-rwxr-xr-x 2 root root 4864 23 juil. 16:23 /usr/bin/python2.6
-rwxr-xr-x 2 root root 4864 23 juil. 16:23 /usr/bin/python
lrwxrwxrwx 1 root root 6 16 août 17:26 /usr/bin/python2 -> python

# ls -ltr /usr/local/bin/python*
-rwxr-xr-x 1 root root 6214485 24 oct. 12:18 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root 1674 24 oct. 12:19 /usr/local/bin/python2.7-config

Installing and configuring distribute (setuptools): 
After installing Python 2.7.6 you also need to install distribute (setuptools) so you can easily install new packages in the right location. 
# sudo wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# sudo /usr/local/bin/python2.7 ez_setup.py
# sudo /usr/local/bin/easy_install-2.7 pip

The commands above will generate the script /usr/local/bin/easy_install-2.7. Use this script to install packages for your new Python version. You should be able to use “easy_install” if “which easy_install” points to the correct 2.7 versions. If this method to install the setuptools does not work, you can follow the link: https://github.com/pypa/setuptools.

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...