【Python】Linux下载并安装Python 3.10版本

avatar
作者
筋斗云
阅读量:0

1. 从Python官网下载源代码

首先,你需要从Python的官方网站(https://www.python.org/downloads/source/)下载Python 3.10的源代码。你可以使用wget命令从命令行下载,例如:

wget https://www.python.org/ftp/python/3.10.x/Python-3.10.0.tgz 

注意替换3.10.x为你想要的具体版本号。

2. 解压源代码包

下载完成后,你需要将源代码包解压到一个目录中,例如/usr/local/。你可以使用tar命令来解压,例如:

tar -xvf Python-3.10.0.tgz -C /usr/local/ 

3. 安装必要的依赖项

在安装Python之前,你需要确保你的系统已经安装了所有必要的编译和构建工具以及Python依赖的库。这可以通过你的Linux发行版的包管理器来完成。例如,在基于Debian的系统(如Ubuntu)上,你可以使用apt命令来安装依赖项:

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

注意,具体的依赖项可能会因你的Linux发行版而有所不同。

4. 编译和安装Python

进入解压后的Python源代码目录,并运行configure脚本来准备编译环境。你可以使用–prefix选项来指定Python的安装目录。然后,运行make命令来编译Python,最后使用make install命令来安装Python。例如:

cd /usr/local/Python-3.10.x   ./configure --prefix=/usr/local/python3.10   make   sudo make install 

5. 验证安装

安装完成后,你可以通过运行python3.10 --version命令来验证Python 3.10是否已成功安装并配置为系统的默认Python版本。如果一切正常,该命令将输出Python的版本号。

注意:

如果你的系统上已经安装了其他版本的Python,并且你想要使用Python 3.10作为默认版本,你可能需要更新你的系统路径(PATH)以包括新安装的Python版本。这可以通过编辑你的shell配置文件(如.bashrc或.bash_profile)并添加类似export PATH=/usr/local/python3.10/bin:$PATH的行来完成。然后,你需要重新加载你的shell配置文件或重新登录以使更改生效。

测试:

/root目录下python3默认为3.11版本

┌──(root㉿kali)-[~] └─# python3 --version    Python 3.11.4  

切换安装目录/usr/local/Python-3.10.0

切到安装目录/usr/local/Python-3.10.0下,python3显示版本为3.10,更新pip

┌──(root㉿kali)-[/usr/local/Python-3.10.0] └─# python3 --version                             pip3 --version Python 3.10.0 pip 21.2.3 from /usr/local/python3.10/lib/python3.10/site-packages/pip (python 3.10)                                                                                                                             ┌──(root㉿kali)-[/usr/local/Python-3.10.0] └─# pip3.10 install --upgrade pip setuptools  Requirement already satisfied: pip in /usr/local/python3.10/lib/python3.10/site-packages (21.2.3) Collecting pip   Downloading pip-24.0-py3-none-any.whl (2.1 MB)      |████████████████████████████████| 2.1 MB 110 kB/s  Requirement already satisfied: setuptools in /usr/local/python3.10/lib/python3.10/site-packages (57.4.0) Collecting setuptools   Downloading setuptools-69.5.1-py3-none-any.whl (894 kB)      |████████████████████████████████| 894 kB 51 kB/s  Installing collected packages: setuptools, pip   Attempting uninstall: setuptools     Found existing installation: setuptools 57.4.0     Uninstalling setuptools-57.4.0:       Successfully uninstalled setuptools-57.4.0   Attempting uninstall: pip     Found existing installation: pip 21.2.3     Uninstalling pip-21.2.3:       Successfully uninstalled pip-21.2.3 Successfully installed pip-24.0 setuptools-69.5.1 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                                                                                                                                                                                                                                                                       ┌──(root㉿kali)-[/usr/local/Python-3.10.0] └─# python3 --version   pip3 --version Python 3.10.0 pip 24.0 from /usr/local/python3.10/lib/python3.10/site-packages/pip (python 3.10)  

运行代码

┌──(root㉿kali)-[/usr/local/Python-3.10.0] └─# python3 whereistheflag.py where is my flag:flag{7f9a2d3c-07de-11ef-be5e-cf1e88674c0b} whereistheflag [108, 117, 72, 80, 64, 49, 99, 19, 69, 115, 94, 93, 94, 115, 71, 95, 84, 89, 56, 101, 70, 2, 84, 75, 127, 68, 103, 85, 105, 113, 80, 103, 95, 67, 81, 7, 113, 70, 47, 73, 92, 124, 93, 120, 104, 108, 106, 17, 80, 102, 101, 75, 93, 68, 121, 26] ----------------------------------------------------------------------- [108, 117, 72, 80, 64, 49, 99, 19, 69, 115, 94, 93, 94, 115, 71, 95, 84, 89, 56, 101, 70, 2, 84, 75, 127, 68, 103, 85, 105, 113, 80, 103, 95, 67, 81, 7, 113, 70, 47, 73, 92, 124, 93, 120, 104, 108, 106, 17, 80, 102, 101, 75, 93, 68, 121, 26] rrrrrrrrrrrright  

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!