How to Install Python on Linux
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 https://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
>>>
https://www.python.org/ftp/python/3.4.0
Index of /ftp/python/3.4.0
最後更新:2017-04-03 12:54:38