Linux中搭建python环境

目录

        1.1 安装运行所依赖的环境

         1.2 python 3 的安装包下载

         1.3 安装所需编译器

         1.4 进入安装

        1.4 安装成功检查文件编译

        1.5 修改文件配置变量位置 

        1.6 启动python

         1.7 总结


        1.1 安装运行所依赖的环境

        使用yum安装所依赖的包:yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

         1.2 python 3 的安装包下载

        输入:wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz,也可以进入这个官网下载其他版本。   

        这里创建在opt目录下可以查看有这个安装包

         解开这个安装包

[root@localhost opt]# tar -zxvf Python-3.7.1.tgz

         1.3 安装所需编译器

        输入:yum install gcc,按y确认安装。

         3.7 版本后需要追加安装:yum install libffi-devel -y

         1.4 进入安装

        进入安装的目录:cd Python-3.7.1  并选择自己需要安装的路径:./configure --  prefix=prefix=/opt/python3

        进入编译

[root@localhost Python-3.7.1]# make

         编译安装

[root@localhost Python-3.7.1]# make install

        1.4 安装成功检查文件编译

[root@localhost python]# /opt/python/bin/python3.7
Python 3.7.1 (default, Oct  6 2021, 14:46:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

        1.5 修改文件配置变量位置 

[root@localhost python]# vim /etc/profile

         添加此内容

# vim ~/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/opt/python/bin

export PATH

        配置完成后输入source ~/.bash_profile 使配置生效

[root@localhost python]# source ~/.bash_profile   

       查看是否可以正常使用

[root@localhost ~]# python3 -V
Python 3.7.1                            
[root@localhost ~]# 

        1.6 启动python

        配置输入python3即可启动

         1.7 总结

        启动或者安装验证时要在python加3如果不会是就会启动Linux自带的,python。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值