PyCharm报错“Python version 3.5 does not support variable annotations”求助(Python3.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 toFile > 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.exeon Windows,/usr/local/bin/python3.7on 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 namedvenvorenvin 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.7Then 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.profilein your home directory) and remove any lines that add Python 3.5 to the PATH. Save the file, then runsource ~/.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) orpyproject.tomlthat hardcode a Python version. Open these files in your project root and make sure they’re set to3.7instead of3.5.Verify the terminal’s Python version
Open PyCharm’s built-in Terminal and run:python --version python3 --versionIf 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

