You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WSL环境中通过控制台将Python升级至最新版本(当前版本为3.8.10)

Upgrading Python to the Latest Version in WSL

Hey there! Upgrading Python on WSL (most folks use Ubuntu-based distros here, which I’ll assume is your case since you’re on 3.8.10) is totally doable with a couple of reliable methods. Let’s walk through them step by step:

Deadsnakes is a trusted PPA that provides up-to-date Python versions for Ubuntu/Debian-based systems. This is the easiest way to get the latest Python without messing with system dependencies.

  • First, update your system’s package list and upgrade existing packages to avoid conflicts:
    sudo apt update && sudo apt upgrade -y
    
  • Install the tools needed to add new PPAs:
    sudo apt install software-properties-common -y
    
  • Add the Deadsnakes PPA to your system:
    sudo add-apt-repository ppa:deadsnakes/ppa -y
    
  • Refresh the package list again to recognize the new PPA’s packages:
    sudo apt update
    
  • Install the latest Python version (replace 3.12 with the actual latest version number, e.g., 3.13 if it’s available):
    sudo apt install python3.12 python3.12-dev python3.12-venv -y
    
  • Optional: Set the new Python version as your default python3 command:
    1. First, check the path of your newly installed Python:
      which python3.12
      
    2. Add it to the system’s alternatives list:
      sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
      
    3. If you have multiple Python versions installed, you can select the default one interactively:
      sudo update-alternatives --config python3
      
      Just enter the number corresponding to your new Python version and hit enter.
  • Verify the upgrade worked:
    python3 --version
    
    You should see the latest version number printed here.

Method 2: Compile from Source (For Custom Configurations)

If you need specific compile-time features or the PPA doesn’t have the version you want, compiling from source is an option. It’s a bit more involved but gives you full control.

  • Install all dependencies required to compile Python:
    sudo apt update && sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget -y
    
  • Download the latest Python source code (replace the URL with the link to the latest version from Python’s official site):
    wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
    
  • Extract the downloaded archive:
    tar -xf Python-3.12.0.tgz
    
  • Navigate into the extracted source directory:
    cd Python-3.12.0
    
  • Configure the build (the --enable-optimizations flag enables performance optimizations, which is recommended):
    ./configure --enable-optimizations
    
  • Compile and install Python (use -j followed by your CPU core count to speed up compilation, e.g., -j4 for a 4-core CPU):
    make -j4
    sudo make altinstall
    
    We use altinstall instead of install to avoid overwriting the system’s default Python version (which could break critical system tools).
  • Verify the installation:
    python3.12 --version
    
    You can also set this as your default using the update-alternatives steps from Method 1 if you’d like.

Important Notes

  • Don’t uninstall the system’s default Python 3.8: Ubuntu relies on this version for many core utilities, removing it could break your WSL instance.
  • When creating virtual environments, make sure to specify the new Python version explicitly, e.g., python3.12 -m venv my_new_env.

内容的提问来源于stack exchange,提问作者Max Jahleel Castillo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 22:39:06