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

如何在Mac OS X上将Python 3设为默认版本?解决Django安装兼容问题

Fixing Python 3 as Default Version to Install Django 2.0.4

Hey there! Let's get your Python 3.6 set as the system default so you can install Django 2.0.4 without hitting that Python 2.7 limitation. The approach varies a bit depending on your operating system, so I'll break it down for both Linux/macOS and Windows:

For Linux or macOS

Method 1: Use update-alternatives (Debian/Ubuntu-based systems)

This is the most reliable way to set a system-wide default Python version:

  • First, check the paths of your Python installations (if you don't know them already):

    which python2.7
    which python3.6
    
  • Register both versions with the alternatives system. The number at the end is the priority—higher numbers mean higher priority:

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
    
  • Now select Python 3.6 as the default:

    sudo update-alternatives --config python
    

    You'll see a list of available versions—type the number next to Python 3.6 and press Enter.

  • Verify the change works:

    python --version
    

    It should show Python 3.6.x.

  • To fix pip too (so it uses Python 3 by default), repeat the process for pip:

    sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip2 1
    sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 2
    sudo update-alternatives --config pip
    

Method 2: Adjust shell configuration (for macOS or non-Debian systems)

If update-alternatives isn't available, you can modify your shell's startup file to set a persistent alias (I'm guessing you tried temporary aliases before—this makes it stick across all sessions):

  • Open your shell config file (.bashrc for Bash, .zshrc for Zsh) in a text editor:
    nano ~/.bashrc
    # or
    nano ~/.zshrc
    
  • Add these lines at the end:
    alias python='/usr/bin/python3.6'
    alias pip='/usr/bin/pip3'
    
  • Save the file and reload the config:
    source ~/.bashrc
    # or
    source ~/.zshrc
    
  • Verify with python --version and pip --version.

For Windows

  • First, find your Python 3.6 installation folder (usually C:\Python36 or C:\Users\YourName\AppData\Local\Programs\Python\Python36).
  • Open System Properties: Right-click "This PC" → "Properties" → "Advanced system settings".
  • Click Environment Variables.
  • In the System variables section, find the Path variable and click "Edit".
  • Move the entries for Python 3.6 (e.g., C:\Python36 and C:\Python36\Scripts) above the entries for Python 2.7.
  • Click "OK" to save all changes.
  • Important: Close any open Command Prompt/PowerShell windows and open a new one.
  • Verify the change:
    python --version
    pip --version
    
    Both should now point to Python 3.6.

Once you've set Python 3 as default, run pip install Django==2.0.4 again—it should work perfectly now!

内容的提问来源于stack exchange,提问作者yoursweater

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 08:30:28