百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

如何在 Ubuntu 20.04|18.04 上安装 Python 3.10

nanshan 2025-02-08 12:11 16 浏览 0 评论

#头条创作挑战赛#

Python 是一种广泛使用的、开源的、面向对象的高级编程语言,拥有庞大的社区。它因其简单易学的语法而受到欢迎。Python 可用于构建所有类型的应用程序,从小而简单的脚本到复杂的机器学习算法。

Python 3.10 是 Python 的最新发布版本,但不如 Python 3.9 稳定,但最终候选版本有望很快完成。Python 3.10 具有以下特性:

  1. 能够直接输入提示列表和字典
  2. 更灵活的装饰器
  3. 删除已弃用的兼容性代码
  4. 更强大的 Python 解析器
  5. 新的 HTTP 状态代码
  6. 适当的时区支持
  7. 安全更新等

Python 的一些主要用途是:

  1. 与软件一起使用以创建工作流程。
  2. 在服务器上用于创建 Web 应用程序。
  3. 快速原型制作或生产就绪软件开发。
  4. 处理大数据并执行复杂的数学运算。
  5. 连接到数据库系统,读取和修改文件。

本指南演示如何在 Ubuntu 20.04|18.04 上安装Python 3.10 。我将介绍两种在 Debian 11|10 系统上安装 Python 3.10 的方法。

  • deadsnakes PPA安装 Python 3.10
  • 源代码手动构建 Python 3.10

入门

确保您的系统已更新并安装了所需的软件包。

sudo apt update && sudo apt upgrade -y

选项 1 – 使用 Apt Repo 在 Ubuntu 20.04|18.04 上安装 Python 3.10

使用 APT 在 Ubuntu 20.04|18.04 上安装 Python 3.10 非常简单,对 deadsnakes 自定义 PPA 赞不绝口!这使得在 Ubuntu 上安装 Python 变得容易,并且能够接收持续的更新、错误修复和安全更新。

安装添加自定义 PPA 所需的依赖项。

sudo apt install software-properties-common -y

然后继续并将 deadsnakes PPA 添加到 APT 包管理器源列表中,如下所示。

sudo add-apt-repository ppa:deadsnakes/ppa

Enter 键继续。

..........
To install 3rd-party Python modules, you should use the common Python packaging tools.  For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
https://packaging.python.org/installing/

Sources
=======
The package sources are available at:
https://github.com/deadsnakes/

Nightly Builds
==============

For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly
 More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Press [ENTER] to continue or ctrl-c to cancel adding it

将 deadsnakes 存储库添加到您的 Ubuntu 20.04|18.04 系统后,现在使用下面的单个命令下载 Python 3.10。

sudo apt install python3.10

依赖树:

...................
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpython3.10-minimal libpython3.10-stdlib python3.10-minimal
Suggested packages:
  python3.10-venv binfmt-support
The following NEW packages will be installed:
  libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal
0 upgraded, 4 newly installed, 0 to remove and 192 not upgraded.
Need to get 5,023 kB of archives.
After this operation, 19.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

通过检查安装的版本来验证安装。

$ python3.10 --version
3.10.9

选项 2 – 从源代码在 Ubuntu 20.04|18.04 上安装 Python 3.10。

在 Ubuntu 20.04|18.04 系统上安装 Python 3.10 的另一种方法是从源代码构建它。使用这种安装方法,您可以保证获得最新的 Python 版本,尽管您将无法通过APT包管理器接收持续的更新、错误修复和安全更新。

安装所需的依赖项以从源代码构建 Python 3.10。

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

现在继续并从Python 官方发布页面下载最新发布的 Python 版本。或者,复制 Python 3.10 gzipped tarball 的下载链接并使用 Wget 提取它,如下所示。

wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz

下载此文件后,继续并解压缩它。

tar -xf Python-3.10.*.tgz

现在导航到提取的目录并运行configure脚本以检查所需的依赖项。–-enable optimization标志通过运行多个测试来优化二进制文件。

cd Python-3.10.*/
./configure --enable-optimizations

输出:

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.10... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out

.....................
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile

现在启动 Python 3.10 构建过程,如下所示。

make -j $(nproc)

请记住,-j 参数应与您系统上的内核数量相匹配,以使进程更快。使用命令检查系统上的内核数nproc。对于这个例子,我的系统上有 2 个内核。

示例输出:

....................
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  pwd                   time               

running build_scripts
copying and adjusting /home/ubuntu/Python-3.10.3/Tools/scripts/pydoc3 -> build/scripts-3.10
copying and adjusting /home/ubuntu/Python-3.10.3/Tools/scripts/idle3 -> build/scripts-3.10
copying and adjusting /home/ubuntu/Python-3.10.3/Tools/scripts/2to3 -> build/scripts-3.10
changing mode of build/scripts-3.10/pydoc3 from 644 to 755
changing mode of build/scripts-3.10/idle3 from 644 to 755
changing mode of build/scripts-3.10/2to3 from 644 to 755
renaming build/scripts-3.10/pydoc3 to build/scripts-3.10/pydoc3.10
renaming build/scripts-3.10/idle3 to build/scripts-3.10/idle3.10
renaming build/scripts-3.10/2to3 to build/scripts-3.10/2to3-3.10
make[1]: Leaving directory '/home/ubuntu/Python-3.10.0'

构建过程完成后,现在发出下面的 make 命令以在 Ubuntu 20.04|18.04 上安装 Python 3.10。

sudo make altinstall

这里 altinstall使用而不是install为了在/usr/bin/python中保留默认的 Python 二进制路径。

示例输出:

Looking in links: /tmp/tmpwbk6rtev
Processing /tmp/tmpwbk6rtev/setuptools-57.4.0-py3-none-any.whl
Processing /tmp/tmpwbk6rtev/pip-21.2.3-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: Value for scheme.headers does not match. Please report this to 
  distutils: /usr/local/include/python3.10/setuptools
  sysconfig: /home/ubuntu/Python-3.10.3/Include/setuptools
  WARNING: Value for scheme.headers does not match. Please report this to 
  distutils: /usr/local/include/python3.10/pip
  sysconfig: /home/ubuntu/Python-3.10.3/Include/pip
Successfully installed pip-21.2.3 setuptools-57.4.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

验证您的安装。

$ python3.10 --version
Python 3.10.9

在 Ubuntu 20.04|18.04 上安装 Python 模块|扩展

模块和扩展在 Python 中很有用,因为它们为它添加了功能。可以使用Python 包管理器(PIP)在 Ubuntu 20.04|18.04 上安装模块。您需要在系统上安装 PIP,如下所示

sudo apt install python3-pip

然后使用以下语法安装所选的 Python 模块。

sudo pip install module-name

在本指南中,我将演示如何安装 Python 模块beautifulsoup4

sudo pip install beautifulsoup4

输出:

Collecting beautifulsoup4
  Downloading beautifulsoup4-4.10.0-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 259 kB/s 
Collecting soupsieve>1.2
  Downloading soupsieve-2.2.1-py3-none-any.whl (33 kB)
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.10.0 soupsieve-2.2.1

您可以使用以下命令列出本地安装的 Python 包:

$ pip list
Package                Version             
---------------------- --------------------
attrs                  19.3.0              
Automat                0.8.0               
beautifulsoup4         4.10.0              
blinker                1.4                 
certifi                2019.11.28          
chardet                3.0.4               
Click                  7.0                 
cloud-init             20.2                
colorama               0.4.3               
command-not-found      0.3                 
configobj              5.0.6               
constantly             15.1.0              
cryptography           2.8                 
dbus-python            1.2.16              
distro                 1.4.0               
distro-info            0.23ubuntu1         
entrypoints            0.3                 
httplib2               0.14.0              
hyperlink              19.0.0     
..............

这就对了!我希望你喜欢这篇关于如何在 Ubuntu 20.04|18.04 上安装 Python 3.10 的指南。您现在可以使用 Python 构建 Web 应用程序、软件开发、创建工作流等

相关推荐

三种自建KMS激活系统自动激活windows方法

第一种:在windows服务器上搭建主要针对vol版本(win7、win10、win20xx、win2012等等)平台:我自己搭建的windows虚拟机,windows2016的操作系统软件:...

重装系统被收98元?避开Windows付费陷阱的实用指南

重装系统被收98元?避开Windows付费陷阱的实用指南有网友反映,在重装Windows系统后,屏幕突然弹出“激活系统需支付98元服务费”的提示,疑惑自己是不是遭遇了付费陷阱。事实上,微软官方的Wi...

Windows Server2012远程桌面服务配置和授权激活

安装:注意:安装完毕之后需手动重启一下计算机配置终端服务管理工具---远程桌面服务---RD授权诊断程序,查看当前服务器有没有授权授权:运行—>gpedit.msc->计算机配置---管理...

新书速览|Windows Server 2022 系统与网站配置实战

讲述桌面体验、ServerCore/NanoServer,容器与云系统的配置1本书内容《WindowsServer2022系统与网站配置实战》秉持作者一贯理论兼具实践的写作风格,以新版的Wi...

Windows激活全攻略:KMS神钥与专业工具的完美结合!

对于许多Windows用户来说,系统的激活是一个必经的过程。虽然Windows操作系统在未经激活的状态下也可以使用一段时间,但长期来看,未激活的系统会限制某些功能并频繁提示用户激活。以下是两种流行的激...

微软Win9全新激活技术曝光(微软系统激活有什么用)

2014-07-0905:46:00作者:徐日俄罗斯Wzor日前披露了更多关于Windows9的最新消息,据悉,Windows9将会在今年秋季亮相,其宣传口号是“想要开始按钮和开始菜单?如你所...

快速激活Windows 10/11:CMD命令详细教程

#记录我的2024#激活Windows操作系统是确保系统功能和安全更新正常运行的重要步骤。本文将为您分享如何使用命令提示符(CMD)在Windows10和Windows11上进行激活的详细步骤。...

Wndows 2019 RDS应用发布部署(rds的安装和应用程序的发布)

安装前的准备1、需要提供服务器作为应用中心,应用中心的推荐配置如下表所示。规格建议1-10人11-20人21-50人51-100人100+人CPU4核8核16核内存8GB16GB32GB64GB系统盘...

解决 Windows 系统激活难题(如何解决windows激活问题)

今天,一位朋友给我说,他手头有三台电脑,均同时弹出系统未激活的提示。他对此毫无头绪,便急忙将电脑上出现的激活提示信息一股脑发给了我。我看到其中一台显示的是“Windows10企业版LTSC尚...

自建KMS激活服务器(自建kms激活服务器的风险)

自建KMS激活服务器Win10和office安装后,都需要激活才可以使用,一般可以输入购买的MAK激活码进行在线激活,也可以通过KMS激活,网上也有很多激活工具,但这些工具一般都含有病毒或木马程序,容...

30秒免费激活windows和office亲测有效!

“第三方工具有病毒?”“KMS服务器激活总失效?”今天给大家分享一个开源激活工具——MicrosoftActivationScripts(MAS),无需密钥、不装软件,30秒永久激活Window...

「操作系统」Windows 10 LTSC 2019 企业版C大集成更新版

Windows10LTSC企业版CHIANNET集成更新优化整合多镜像版,CHIANNET,是USBOS超级PE维护盘工具箱作者,长久以来一直默默的更新着,USBOSPE软件,电脑城装机及...

一文看懂Windows激活:自查方法+授权类型科普(Win7/Win10通用)

一、如何判断Windows是否永久激活?无论是Win7还是Win10,均可通过以下方法快速验证:命令提示符法(通用):按下Win+R,输入slmgr.vbs/xpr并按回车键运行即可查看是否...

部分Windows Server 2019/2022用户反馈无法运行微软Teams应用

IT之家7月2日消息,科技媒体borncity今天(7月2日)发布博文,报道称在多个WindowsServer版本上,MicrosoftTeams应用近期出现了运行故障。用...

这种Windows激活方式已有20年...(windows现在激活)

2006年微软正式发布WindowsVista,随之而来引入了一项新的激活机制「OEM激活」,这项机制在Vista和Win7上最为流行。其实WindowsServer自2008开始至2025版本一...

取消回复欢迎 发表评论: