Summary
Hostmonster uses the preinstalled version of Python that ships with CentOS. Because of this it is often not the latest release. This article will explain how to install an updated version of python locally.
Download Python
Enter the following commands to download and extract Python 2.7 to your hosting account.
下载安装的过程基本在这里
1.建立一个文件夹保存下载的压缩包,进入之后下载;
2.然后解压缩
3.进入解压缩之后的文件夹准备安装
mkdir ~/python
cd ~/python
wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0b1.tgz
tar zxfv Python-3.4.0b1.tgz
find ~/python -type d | xargs chmod 0755
cd Python-3.4
Install Python
Once extracted you can use the following commands to configure and install Python.
./configure --prefix=$HOME/python
make
make install
5.开始安装
Modify the .bashrc
For your local version of python to load you will need to add it to the .bashrc file.
vim ~/.bashrc
Press i ,than Enter:
export PATH=$HOME/python/bin:$PATH
Write the changes and close vim:
:wq
Press Enter
source ~/.bashrc
Note: You may need to logout for the environment to update.
Enter python -V
to check the version of python installed.
6.设置环境变量。
【注意】 以上的操作都完成之后,但是由于linux原来就有一个版本的 python,这时候查看版本会发现,仍然是原来的版本,新的还是看不到。需要作如下操作。
1.再将原来/usr/bin/python链接改为别的名字
1 |
mv /usr/bin/python /usr/bin/python_old |
python
把这个移动到原来链接位置(链接过去 ln)
再建立新版本python的链接
1 |
ln -s /新版python的路径 /bin/python2.7 /usr/bin/python |
3. 现在ok了,可以查询了。
python -V 可以看到信版本了
Python 3.4.0b1 (default, Jan 20 2014, 20:35:22)
[GCC 4.4.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
import 'atexit' # <class '_frozen_importlib.BuiltinImporter'>
# destroy atexit
>>>
http://www.python.org/ftp/python/3.4.0