首页 > 解决方案 > 从源码安装 Python3.7

问题描述

我需要使用 Python3.7,所以我按照这些说明进行安装

curPath=${pwd}
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tgz
cd Python-3.7.9
sudo ./configure --enable-optimizations
cd ${pwd}

然后我尝试运行python -V并得到

Command 'python3.7' not found, did you mean:

  command 'python2.7' from deb python2.7 (2.7.18-1~20.04)
  command 'python3.9' from deb python3.9 (3.9.0-5~20.04)
  command 'python3.8' from deb python3.8 (3.8.5-1~20.04.2)

Try: sudo apt install <deb name>

我也试着跑whereis python

whereis python
python: /usr/bin/python3.8 /usr/bin/python3.8-config /usr/lib/python3.8 /usr/lib/python2.7 /usr/lib/python3.9 /etc/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8

标签: pythonamazon-web-servicesubuntu

解决方案


我将您的脚本调整为在 Ubuntu 20.04 实例上用作UserData脚本:

#!/bin/bash

apt update
apt install -y build-essential zlib1g-dev

curPath=${pwd}
cd /usr/src
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
tar xzf Python-3.7.9.tgz
cd Python-3.7.9
#./configure --enable-optimizations
./configure 
make
make install
cd ${pwd}

推荐阅读