Python 3.7安全完全卸载咨询:virtualenv安装TensorFlow相关问题
Hey there, I’ve been in this exact spot before—accidentally leaving behind a Python version that’s cluttering things up, especially when working with virtualenvs. Let’s break down how to safely clean up that Python 3.7 installation without messing up your system.
First, Critical Warning
Never touch anything under /System/Library/Frameworks/Python.framework—that’s Apple’s system-native Python, and deleting or modifying it will break core macOS functionality. We’re only targeting your user-installed Python 3.7 in /Library (no leading System).
Step 1: Stop All Python 3.7 Processes
Before deleting anything, make sure no programs or terminal sessions are using Python 3.7. Run this in Terminal to check for active processes:
ps aux | grep python3.7
If you see any results (other than the grep command itself), kill the process with:
kill <PID_NUMBER>
Replace <PID_NUMBER> with the number in the second column of the output.
Step 2: Delete the Python 3.7 Framework
This is the main installation directory for your user-installed Python 3.7:
sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.7
You’ll need to enter your admin password when prompted.
Step 3: Clean Up Python 3.7 Links in /usr/local/bin
User-installed Python adds symlinks to /usr/local/bin for easy access. First, list all links pointing to your Python 3.7 installation:
ls -l /usr/local/bin | grep "../Library/Frameworks/Python.framework/Versions/3.7"
Then delete those links with a batch command (or delete them one by one if you want to be extra cautious):
cd /usr/local/bin && sudo rm -f $(ls -l | grep "../Library/Frameworks/Python.framework/Versions/3.7" | awk '{print $9}')
Step 4: Remove Leftover Package Directories
Any Python packages you installed for 3.7 will be in /Library/Python/3.7—you can safely delete this too:
sudo rm -rf /Library/Python/3.7
Step 5: Fix Your Virtualenv
Since your TensorFlow virtualenv was based on this Python 3.7, it’s now useless. Delete the virtualenv folder (replace tf_env with your actual virtualenv name):
rm -rf tf_env
Then create a new virtualenv using your desired Python version (e.g., Python 3.8+ which supports newer TensorFlow versions) and reinstall TensorFlow.
Double-Check Before You Delete
If you’re ever unsure if a file is system-owned, run ls -l <path>—system files will have root or wheel as the owner, but user-installed Python files should have your username. When in doubt, skip that file!
内容的提问来源于stack exchange,提问作者Muhsin Alabbas

