终端Python版本切换咨询:卸载残留及PyCharm检测不到Python3.7问题
Hey Kayla, let's tackle your questions one by one to get everything working smoothly again!
Why do MAMP/Python 2.7 traces still show up in Terminal after uninstall?
There are a few common reasons for this:
- System-preinstalled Python 2.7: If you're on a macOS version older than Monterey, Apple preinstalls Python 2.7 by default. Uninstalling your manually installed Python 2.7 won't remove this system version, so
pythonmight still point to it. - Residual environment variables: MAMP and custom Python installs often add paths to your shell configuration files (like
~/.bash_profile,~/.zshrc, or~/.profile). If you didn't delete these entries during uninstall, Terminal will still look for the old programs in those paths. - Shell command cache: Terminal stores command paths in a hash table to speed things up. Even after you delete the program, the cached path might still exist, making it seem like the old version is still there.
How to set Python 3.7 as Terminal's default version?
Follow these steps:
- First, find where Python 3.7 is installed by running this command:
You'll get a path likewhich python3.7/usr/local/bin/python3.7– note this down. - Update your shell configuration:
- If you use Bash: Open
~/.bash_profilein a text editor, add this line (replace the path with your actual one):
Save the file, then runalias python="/usr/local/bin/python3.7"source ~/.bash_profileto apply the changes immediately. - If you use Zsh: Do the same but edit
~/.zshrcinstead, then runsource ~/.zshrc.
Alternatively, you can prioritize the Python 3.7 path in yourPATHvariable (more robust for scripts):
(Make sureexport PATH="/usr/local/bin:$PATH"/usr/local/binis the folder containing your python3.7 executable.) - If you use Bash: Open
- Clear the shell cache to avoid old paths sticking around:
hash -r - Verify the change: Close and reopen Terminal, then run
python --version– it should show Python 3.7.
Fixing PyCharm not detecting Python 3.7
Try these steps to get PyCharm to recognize your Python 3.7 install:
- Manually add the interpreter:
- Open PyCharm, go to
File > Settings(Windows/Linux) orPyCharm > Preferences(macOS). - Navigate to
Project: [Your Project Name] > Python Interpreter. - Click the gear icon in the top-right corner, select
Add. - Choose
System Interpreter, then click the...button to browse for your Python 3.7 executable (use the path you found earlier withwhich python3.7). Select it and clickOK.
- Open PyCharm, go to
- Check PyCharm compatibility: Make sure your PyCharm version supports Python 3.7 – versions 2019.1 and newer do. If you're on an older version, consider updating PyCharm.
- Confirm Python 3.7 is properly installed: Run
python3.7 -m pip --versionin Terminal. If this returns an error, your Python 3.7 install might be corrupted – try reinstalling it. - Restart PyCharm: Sometimes the IDE needs a fresh start to pick up new interpreters.
内容的提问来源于stack exchange,提问作者kayla
相关产品推荐
相关产品推荐

