如何在centos安装python
2个回答
展开全部
centos一般自带了python2.7,如果你想安装python3的话,可以按照以下步骤安装,以python3.6.2为例:
1. 安装Python依赖包:
#yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2. 下载Python源码包:
#cd /usr/local/src
#wget
3. 编译、安装:
[root@Python /]# tar -xzvf /usr/local/src/Python-3.6.2.tgz -C /usr/local/src/
[root@Python /]# cd /usr/local/src/Python-3.6.2
[root@Python Python-3.6.2]# ./configure --prefix=/usr/local/python --enable-shared
[root@Python Python-3.6.2]# make
[root@Python Python-3.6.2]# make install
4. 如果在安装Python时使用了--enable-share命令后启动时会出错误:
ImportError:libpython3.6m.so.1.0:cannot open shared object file: No such file or directory
解决办法是在运行configure和make之前运行:
export LD_LIBRARY_PATH={prefix}/lib/
{prefix} is what you passed to --prefix.
例如:#export LD_LIBRARY_PATH=/usr/local/python/lib/
#vim ~/.bash_profile
添加一行:
export LD_LIBRARY_PATH=/usr/local/python/lib:$LD_LIBRARY_PATH
5. 添加Python命令到环境变量:
[root@Python /]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/python/bin
6. 使环境变量生效:
[root@Python /]# source ~/.bash_profile
7. 查看Python版本:
[root@Python /]# python3 -V
Python 3.6.2
8. 更改系统默认python版本为Python3.6
[root@Python /]# mv /usr/bin/python /usr/bin/python2.7.5
[root@Python /]# ln -s /usr/local/python/bin/python3.6 /usr/bin/python
9. 核对Python版本:
[root@Python /]# python -V
Python 3.6.2
10. 解决python升级后,YUM不能正常工作的问题:
#vi /usr/bin/yum
将文件头部的#!/usr/bin/python
改成 #!/usr/bin/python2.7
1. 安装Python依赖包:
#yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2. 下载Python源码包:
#cd /usr/local/src
#wget
3. 编译、安装:
[root@Python /]# tar -xzvf /usr/local/src/Python-3.6.2.tgz -C /usr/local/src/
[root@Python /]# cd /usr/local/src/Python-3.6.2
[root@Python Python-3.6.2]# ./configure --prefix=/usr/local/python --enable-shared
[root@Python Python-3.6.2]# make
[root@Python Python-3.6.2]# make install
4. 如果在安装Python时使用了--enable-share命令后启动时会出错误:
ImportError:libpython3.6m.so.1.0:cannot open shared object file: No such file or directory
解决办法是在运行configure和make之前运行:
export LD_LIBRARY_PATH={prefix}/lib/
{prefix} is what you passed to --prefix.
例如:#export LD_LIBRARY_PATH=/usr/local/python/lib/
#vim ~/.bash_profile
添加一行:
export LD_LIBRARY_PATH=/usr/local/python/lib:$LD_LIBRARY_PATH
5. 添加Python命令到环境变量:
[root@Python /]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/python/bin
6. 使环境变量生效:
[root@Python /]# source ~/.bash_profile
7. 查看Python版本:
[root@Python /]# python3 -V
Python 3.6.2
8. 更改系统默认python版本为Python3.6
[root@Python /]# mv /usr/bin/python /usr/bin/python2.7.5
[root@Python /]# ln -s /usr/local/python/bin/python3.6 /usr/bin/python
9. 核对Python版本:
[root@Python /]# python -V
Python 3.6.2
10. 解决python升级后,YUM不能正常工作的问题:
#vi /usr/bin/yum
将文件头部的#!/usr/bin/python
改成 #!/usr/bin/python2.7
2022-08-14
展开全部
建议 直接在centos上执行
yum install python3 python3-devel python3-pip
希望可以帮助你,请采纳,谢谢
yum install python3 python3-devel python3-pip
希望可以帮助你,请采纳,谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询