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

PyCharm报错“Python version 3.5 does not support variable annotations”求助(Python3.7)

Fixing "Python version 3.5 does not support variable annotations" Error with Python 3.7

Oh man, I’ve been exactly where you are—uninstalled Python 3.5, triple-checked PyCharm’s interpreter settings, restarted a dozen times, and still got that annoying error. Let’s walk through the fixes that finally worked for me:

  • Double-check your interpreter’s actual path
    Don’t just trust that you selected "Python 3.7" in PyCharm. Go to File > Settings > Project: <your-project-name> > Python Interpreter, click the gear icon next to the interpreter, select "Show All", then check the path listed for your 3.7 interpreter. Sometimes PyCharm might have a stale entry pointing to a leftover Python 3.5 executable or a broken shortcut. If that’s the case, remove the old entry and add the correct path manually (e.g., C:\Python37\python.exe on Windows, /usr/local/bin/python3.7 on macOS/Linux).

  • Wipe and recreate your virtual environment
    If you’re using a virtual environment (venv, conda, etc.), it’s possible the environment was originally created with Python 3.5 and isn’t picking up the new version. Delete the existing environment folder (usually named venv or env in your project root), then create a new one with Python 3.7:

    # For venv
    python3.7 -m venv venv
    # For conda
    conda create -n myenv python=3.7
    

    Then go back to PyCharm’s interpreter settings and select this new environment’s Python executable.

  • Clean up your system’s environment variables
    Even if you uninstalled Python 3.5, its path might still linger in your system’s PATH variable.

    • Windows: Right-click "This PC" > "Properties" > "Advanced System Settings" > "Environment Variables". Look for any entries pointing to Python 3.5 in the "Path" list under either user or system variables, delete them, then restart your computer (this step is crucial—changes might not take effect until you reboot).
    • macOS/Linux: Open your shell config file (.bashrc, .zshrc, or .profile in your home directory) and remove any lines that add Python 3.5 to the PATH. Save the file, then run source ~/.bashrc (or the corresponding file for your shell) to apply changes immediately.
  • Force PyCharm to fully reset its cache
    The standard "Clear Cache" might not cut it—try the nuclear option: File > Invalidate Caches..., then select "Invalidate and Restart". This will wipe all cached interpreter data and force PyCharm to re-scan your system for Python installations from scratch.

  • Check for project-specific version locks
    Some projects use files like .python-version (for pyenv) or pyproject.toml that hardcode a Python version. Open these files in your project root and make sure they’re set to 3.7 instead of 3.5.

  • Verify the terminal’s Python version
    Open PyCharm’s built-in Terminal and run:

    python --version
    python3 --version
    

    If either outputs 3.5, that means your terminal is still using the old version, which can interfere with PyCharm’s background processes. Fix your shell’s PATH as mentioned earlier, then restart the terminal.

If none of these work, the last resort is to fully uninstall PyCharm (including deleting its config folders—on Windows that’s C:\Users\<your-username>\.PyCharm<version>, on macOS/Linux it’s ~/.PyCharm<version>) and reinstall it. But in my case, the first three steps fixed it.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 09:26:52