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 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)