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

MacOS下已安装Django,但python -m django --version报错找不到模块

Fixing "No module named django" Error When Running python -m django --version on macOS

Hey Dave, let's break down why you're seeing this mismatch and fix it quickly:

The Root Cause

On macOS, the default python command usually points to the system's built-in Python 2.x version, while your Django is installed under Python 3.6 (as shown in the error path: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3). That's why pip freeze and django-admin.py version work (they're linked to your Python 3.6 environment) but python -m django --version doesn't—it's checking the wrong Python installation.

Step-by-Step Fixes

  • Use the correct Python executable explicitly
    Instead of python, run the command with python3 to target your Python 3.6 environment:

    python3 -m django --version
    

    This should immediately show your Django 1.11.20 version, since python3 maps to the same Python installation where pip installed Django.

  • Verify the pip-Python connection
    Double-check that your pip is associated with Python 3.6 by running:

    pip --version
    

    The output should show a path pointing to /Library/Frameworks/Python.framework/Versions/3.6/...—this confirms pip is installing packages to the right Python environment.

  • Make python default to Python 3.6 (optional)
    If you want to avoid typing python3 every time, you can set an alias in your shell configuration:

    1. Open your shell config file (for Bash: ~/.bash_profile; for Zsh: ~/.zshrc) in a text editor.
    2. Add this line:
      alias python='/Library/Frameworks/Python.framework/Versions/3.6/bin/python3'
      
    3. Save the file and reload the config with:
      source ~/.bash_profile  # or source ~/.zshrc for Zsh
      

    Now running python -m django --version will use your Python 3.6 environment and find Django.

  • Test with the full Python path
    If the above doesn't work for some reason, use the full path to your Python 3.6 executable to guarantee it targets the right environment:

    /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 -m django --version
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 09:24:25