如何在 Mac OS X 10.6.4 上卸载 Python 2.7?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3819449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to uninstall Python 2.7 on a Mac OS X 10.6.4?
提问by Jan Deinhard
I want to completely remove Python 2.7 from my Mac OS X 10.6.4. I managed to remove the entry from the PATHvariable by reverting my .bash_profile. But I also want to remove all directories, files, symlinks, and entries that got installed by the Python 2.7 install package. I've got the install package from http://www.python.org/. What directories/files/configuration file entries do I need to remove? Is there a list somewhere?
我想从我的 Mac OS X 10.6.4 中完全删除 Python 2.7。我设法PATH通过恢复我的.bash_profile. 但我也想删除 Python 2.7 安装包安装的所有目录、文件、符号链接和条目。我从http://www.python.org/获得了安装包。我需要删除哪些目录/文件/配置文件条目?某处有清单吗?
采纳答案by Ned Deily
Do not attempt to remove any Apple-supplied system Python which are in /System/Libraryand /usr/bin, as this may break your whole operating system.
不要尝试删除任何 Apple 提供的在/System/Library和 中的系统 Python /usr/bin,因为这可能会破坏您的整个操作系统。
NOTE:The steps listed below do notaffect the Apple-supplied system Python 2.7; they only remove a third-party Python framework, like those installed by python.org installers.
注意:下面列出的步骤不会影响 Apple 提供的系统 Python 2.7;他们只删除第三方 Python 框架,例如由python.org installers 安装的框架。
The complete list is documented here. Basically, all you need to do is the following:
完整列表记录在此处。基本上,您需要做的就是以下几点:
Remove the third-party Python 2.7 framework
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7Remove the Python 2.7 applications directory
sudo rm -rf "/Applications/Python 2.7"Remove the symbolic links, in
/usr/local/bin, that point to this Python version. See them usingls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7'and then run the following command to remove all the links:
cd /usr/local/bin/ ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print }' | tr -d @ | xargs rmIf necessary, edit your shell profile file(s) to remove adding
/Library/Frameworks/Python.framework/Versions/2.7to yourPATHenvironment file. Depending on which shell you use, any of the following files may have been modified:~/.bash_login,~/.bash_profile,~/.cshrc,~/.profile,~/.tcshrc, and/or~/.zprofile.
删除第三方 Python 2.7 框架
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7删除 Python 2.7 应用程序目录
sudo rm -rf "/Applications/Python 2.7"删除
/usr/local/bin指向此 Python 版本的符号链接 in 。看到他们使用ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7'然后运行以下命令删除所有链接:
cd /usr/local/bin/ ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print }' | tr -d @ | xargs rm如有必要,编辑您的 shell 配置文件以删除添加
/Library/Frameworks/Python.framework/Versions/2.7到您的PATH环境文件中的内容。根据您所使用的shell,任何下列文件可能已被修改:~/.bash_login,~/.bash_profile,~/.cshrc,~/.profile,~/.tcshrc,和/或~/.zprofile。
回答by conehead
This one works:
这个有效:
cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print }' | tr -d @ | xargs rm
Description:
It list all the links, removes @character and then removes them.
描述:它列出所有链接,删除@字符,然后删除它们。
回答by Gabriel Mazetto
If you installed it using the PKG installer, you can do:
如果您使用 PKG 安装程序安装它,您可以执行以下操作:
pkgutil --pkgs
or better:
或更好:
pkgutil --pkgs | grep org.python.Python
which will output something like:
这将输出如下内容:
org.python.Python.PythonApplications-2.7
org.python.Python.PythonDocumentation-2.7
org.python.Python.PythonFramework-2.7
org.python.Python.PythonProfileChanges-2.7
org.python.Python.PythonUnixTools-2.7
you can now select which packages you will unlink (remove).
您现在可以选择要取消链接(删除)的包。
This is the unlink documentation:
这是取消链接文档:
--unlink package-id
Unlinks (removes) each file referenced by package-id. WARNING: This command makes no attempt to perform reference counting or dependency analy-
sis. It can easily remove files required by your system. It may include unexpected files due to package tainting. Use the --files command first
to double check.
In my example you will type
在我的示例中,您将键入
pkgutil --unlink org.python.Python.PythonApplications-2.7
pkgutil --unlink org.python.Python.PythonDocumentation-2.7
pkgutil --unlink org.python.Python.PythonFramework-2.7
pkgutil --unlink org.python.Python.PythonProfileChanges-2.7
pkgutil --unlink org.python.Python.PythonUnixTools-2.7
or in one single line:
或在一行中:
pkgutil --pkgs | grep org.python.Python | xargs -L1 pkgutil -f --unlink
Important: --unlink is not available anymore starting with Lion (as of Q1`2014 that would include Lion, Mountain Lion, and Mavericks). If anyone that comes to this instructions try to use it with lion, should try instead to adapt it with what this post is saying: https://wincent.com/wiki/Uninstalling_packages_(.pkg_files)_on_Mac_OS_X
重要提示:--unlink 从 Lion 开始不再可用(截至 2014 年第一季度,将包括 Lion、Mountain Lion 和 Mavericks)。如果遇到此说明的任何人尝试将它与 Lion 一起使用,则应尝试将其与这篇文章的内容相适应:https: //wincent.com/wiki/Uninstalling_packages_(.pkg_files)_on_Mac_OS_X
回答by minhas23
No need to uninstall old python versions.
无需卸载旧的 python 版本。
Just install new version say python-3.3.2-macosx10.6.dmg and change the soft link of python to newly installed python3.3
只需安装新版本说python-3.3.2-macosx10.6.dmg并将python的软链接更改为新安装的python3.3
Check the path of default python and python3.3 with following commands
使用以下命令检查默认python和python3.3的路径
"which python" and "which python3.3"
“哪个python”和“哪个python3.3”
then delete existing soft link of python and point it to python3.3
然后删除python现有的软链接并将其指向python3.3
回答by user86559
In regards to deleting the symbolic links, I found this to be useful.
关于删除符号链接,我发现这很有用。
find /usr/local/bin -lname '../../../Library/Frameworks/Python.framework/Versions/2.7/*' -delete
回答by John Mulhall
Note: If you installed Python using Homebrew, then you can follow the following steps, otherwise look for another solution!
注意:如果您使用 Homebrew 安装 Python,那么您可以按照以下步骤操作,否则请寻找其他解决方案!
To uninstall Python 2.7.10 which you installed using Homebrew, then you can simply issue the following command:
要卸载使用 Homebrew 安装的 Python 2.7.10,只需发出以下命令:
brew uninstall python
Similarly, if you want to uninstall Python 3 (which you installed using Homebrew):
同样,如果要卸载 Python 3(使用 Homebrew 安装):
brew uninstall --force python3
回答by Daniel Lee
Trying to uninstall Python with
尝试卸载 Python
brew uninstall python
will notremove the natively installed Python but rather the version installed with brew.
将不会删除本机安装了Python,而是版本安装brew。
回答by A Q
Onur Güzel provides the solution in his blog post, "Uninstall Python Package from OS X.
Onur Güzel 在他的博客文章“从 OS X 卸载 Python 包”中提供了解决方案。
You should type the following commands into the terminal:
您应该在终端中键入以下命令:
sudo rm -rf /Library/Frameworks/Python.frameworkcd /usr/local/binls -l . | grep '../Library/Frameworks/Python.framework' | awk '{print $9}' | xargs sudo rmsudo rm -rf "/Applications/Python x.y"where command x.y is the version of Python installed. According to your question, it should be 2.7.
sudo rm -rf /Library/Frameworks/Python.frameworkcd /usr/local/binls -l . | grep '../Library/Frameworks/Python.framework' | awk '{print $9}' | xargs sudo rmsudo rm -rf "/Applications/Python x.y"其中命令 xy 是安装的 Python 版本。根据你的问题,应该是2.7。
In Onur's words:
用奥努尔的话来说:
WARNING:This commands will remove all Python versions installed with packages. Python provided from the system will not be affected.
警告:此命令将删除所有随包安装的 Python 版本。系统提供的 Python 不会受到影响。
If you have more than 1 Python version installed from python.org, then run the fourth command again, changing "x.y" for each version of Python that is to be uninstalled.
如果您从 python.org 安装了 1 个以上的 Python 版本,则再次运行第四个命令,为要卸载的每个 Python 版本更改“xy”。
回答by Roberto Manfreda
No need to uninstall it or going crazy with symbolic links, just use an alias. I faced the same problem when upgrading to python 3.7.1.
Just install the new python version using brew install pythonthen in your .bash_profilecreate an alias pointing to the new python version; like this: alias python="/usr/local/bin/python3"then save and run source ~/.bash_profile.
Done.
无需卸载它或使用符号链接发疯,只需使用alias. 升级到 python 3.7.1 时我遇到了同样的问题。
只需使用brew install pythonthen安装新的 python 版本,然后在.bash_profile创建一个指向新 python 版本的别名;像这样:alias python="/usr/local/bin/python3"然后保存并运行source ~/.bash_profile。
完毕。
回答by F1Linux
If you're thinking about manually removing Apple's default Python 2.7, I'd suggest you hang-fire and do-noting: Looks like Apple will very shortly do it for you:
如果您正在考虑手动删除 Apple 的默认 Python 2.7,我建议您挂起并注意:看起来 Apple 很快就会为您完成此操作:
Python 2.7 Deprecated in OSX 10.15 Catalina
Python 2.7 在 OSX 10.15 Catalina 中已弃用
Python 2.7- as well as Ruby & Perl- are deprecated in Catalina: (skip to section "Scripting Language Runtimes" > "Deprecations")
Python 2.7- 以及 Ruby 和 Perl- 在 Catalina 中已弃用:(跳至“脚本语言运行时”>“弃用”部分)
https://developer.apple.com/documentation/macos_release_notes/macos_catalina_10_15_release_notes
https://developer.apple.com/documentation/macos_release_notes/macos_catalina_10_15_release_notes
Apple To Remove Python 2.7 in OSX 10.16
苹果将在 OSX 10.16 中删除 Python 2.7
Indeed, if you do nothing at all, according to The Mac Observer, by OSX version 10.16, Python 2.7 will disappear from your system:
事实上,如果你什么都不做,根据Mac Observer 的说法,到 OSX 10.16 版,Python 2.7 将从你的系统中消失:
https://www.macobserver.com/analysis/macos-catalina-deprecates-unix-scripting-languages/
https://www.macobserver.com/analysis/macos-catalina-deprecates-unix-scripting-languages/
Given this revelation, I'd suggest the best course of action is do nothing and wait for Apple to wipe it for you. As Apple is imminently about to remove it for you, doesn't seem worth the risk of tinkering with your Python environment.
鉴于这一启示,我建议最好的做法是什么都不做,等待苹果为你抹去它。由于 Apple 即将为您删除它,因此似乎不值得冒险修改您的 Python 环境。
NOTE: I see the question relates specifically to OSX v 10.6.4, but it appears this question has become a pivot-point for all OSX folks interested in removing Python 2.7 from their systems, whatever version they're running.
注意:我看到这个问题特别与OSX v 10.6.4 相关,但对于所有有兴趣从他们的系统中删除 Python 2.7 的 OSX 人员来说,这个问题似乎已经成为一个支点,无论他们运行的是什么版本。

