如何在CentOS 7 中搭建Python 3.0 环境

1、下载

通过https://www.python.org/ftp/python/下载Python安装包,这里下载Python-3.10.9.tgz

2、上传

借助MobaXterm等工具将Python安装包上传至/opt目录;

3、解压

将JDK压缩文件解压至/opt目录:tar -xvf /opt/Python-3.10.9.tgz -C /opt

4、删除

删除压缩文件:rm -f /opt/Python-3.10.9.tgz

5、依赖

原因

①、Python-3.10.9.tgz只是Python源码,需要先编译,才能安装,所以需要安装gcc;

②、编译安装Python期间需要诸如ncurses-devel和sqlite-devel等环境,否则提示如下信息:

在这里插入图片描述

安装

# yum -y install gcc ncurses-devel sqlite-devel readline-devel zlib-devel libffi-devel bzip2-devel tk-devel lzma gdbm-devel xz-devel
6、OpenSSL

原因

安装Python 3 前必须先安装OpenSSL,否则编译安装Python3时提示如下信息:

在这里插入图片描述

安装

# yum -y install epel-release
# yum -y install openssl-devel openssl11 openssl11-devel

# 设置最新openssl库编译环境
# export CFLAGS=$(pkg-config --cflags openssl11)
# export LDFLAGS=$(pkg-config --libs openssl11)

注意:

必须先执行yum -y install epel-release,再执行yum -y install openssl11-devel,两条yum命令不要合起来一起执行,否则执行export命令时提示No package ‘openssl11’ found错误。

7、安装
# cd /opt/Python-3.10.9
# ./configure --prefix=/usr/local/python-3.10.9/
# make && make install

说明:–prefix 指定软件安装路径

8、环境
# tee >> /etc/profile << EOF
export PATH=/usr/local/python-3.10.9/bin:$PATH
EOF
# source /etc/profile
9、检查
[root@localhost Python-3.10.9]# python3 -V
Python 3.10.9
[root@localhost Python-3.10.9]# pip3 install pymysql -i https://mirrors.aliyun.com/pypi/simple/
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pymysql
  Downloading https://mirrors.aliyun.com/pypi/packages/e5/30/20467e39523d0cfc2b6227902d3687a16364307260c75e6a1cb4422b0c62/PyMySQL-1.1.0-py3-none-any.whl (44 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.8/44.8 kB 298.5 kB/s eta 0:00:00
Installing collected packages: pymysql
Successfully installed pymysql-1.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip available: 22.3.1 -> 23.3.2
[notice] To update, run: pip3 install --upgrade pip
[root@localhost Python-3.10.9]#

相关推荐

  1. 如何CentOS 7Redis Cluster ?

    2024-01-17 10:22:04       40 阅读
  2. 如何CentOS 7Redis Sentinel ?

    2024-01-17 10:22:04       32 阅读
  3. Centos 7.9 服务器环境

    2024-01-17 10:22:04       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-17 10:22:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-17 10:22:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-17 10:22:04       87 阅读
  4. Python语言-面向对象

    2024-01-17 10:22:04       96 阅读

热门阅读

  1. Python爬虫---scrapy框架---下载嵌套数据

    2024-01-17 10:22:04       42 阅读
  2. 基于冯·诺依曼架构能否实现有主动思想的AI

    2024-01-17 10:22:04       56 阅读
  3. [HarmonyOS]主题课:使用DevEco Studio高效开发

    2024-01-17 10:22:04       51 阅读
  4. CMAKE学习

    2024-01-17 10:22:04       59 阅读
  5. 入门级的 DataV 教程,适用于 Vue 2

    2024-01-17 10:22:04       51 阅读
  6. C Primer Plus(第六版)12.9 编程练习 第5题

    2024-01-17 10:22:04       46 阅读
  7. Linux C语言开发(二)C语言数据类型

    2024-01-17 10:22:04       38 阅读
  8. Linux———ifconfig命令详解

    2024-01-17 10:22:04       49 阅读
  9. BFS(广度优先搜索)_层序遍历&最短路径_总结

    2024-01-17 10:22:04       54 阅读
  10. 如何引用R语言版本以及R包版本

    2024-01-17 10:22:04       59 阅读