简体   繁体   English

如何在 Mac OS X 10.6.4 上卸载 Python 2.7?

[英]How to uninstall Python 2.7 on a Mac OS X 10.6.4?

I want to completely remove Python 2.7 from my Mac OS X 10.6.4.我想从我的 Mac OS X 10.6.4 中完全删除 Python 2.7。 I managed to remove the entry from the PATH variable by reverting my .bash_profile .我设法通过恢复我的.bash_profilePATH变量中删除条目。 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/ .但我也想删除由 Python 2.7 安装 package 安装的所有目录、文件、符号链接和条目。我从http://www.python.org/ 安装了 package What directories/files/configuration file entries do I need to remove?我需要删除哪些目录/文件/配置文件条目? Is there a list somewhere?某处有清单吗?

Do not attempt to remove any Apple-supplied system Python which are in /System/Library and /usr/bin , as this may break your whole operating system.不要尝试删除/System/Library/usr/bin中的任何 Apple 提供的系统 Python,因为这可能会破坏您的整个操作系统。


NOTE: The steps listed below do not affect the Apple-supplied Python 2.7;注意:下面列出的步骤不会影响 Apple 提供的 Python 2.7; they only remove a third-party Python framework, like those installed by python.org installers .他们只删除第三方 Python 框架,例如python.org 安装程序安装的框架。


The complete list is documented here .完整列表记录在此处 Basically, all you need to do is the following:基本上,您需要做的就是以下几点:

  1. Remove the third-party Python 2.7 framework去除第三方 Python 2.7 框架

     sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
  2. Remove the Python 2.7 applications directory删除Python 2.7应用程序目录

     sudo rm -rf "/Applications/Python 2.7"
  3. Remove the symbolic links, in /usr/local/bin , that point to this Python version.删除/usr/local/bin中指向此 Python 版本的符号链接。 See them using看他们用

     ls -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 $9}' | tr -d @ | xargs rm
  1. If necessary, edit your shell profile file(s) to remove adding /Library/Frameworks/Python.framework/Versions/2.7 to your PATH environment file.如有必要,编辑您的 shell 配置文件以删除将/Library/Frameworks/Python.framework/Versions/2.7添加到您的PATH环境文件中。 Depending on which shell you use, any of the following files may have been modified: ~/.bash_login , ~/.bash_profile , ~/.cshrc , ~/.profile , ~/.tcshrc , ~/.zshrc , and/or ~/.zprofile .根据您使用的 shell,以下任何文件可能已被修改: ~/.bash_login~/.bash_profile~/.cshrc~/.profile~/.tcshrc~/.zshrc和/或~/.zprofile

This one works:这个有效:

cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm

Description: It list all the links, removes @ character and then removes them.描述:它列出所有链接,删除@字符,然后删除它们。

Create the symlink to latest version创建指向最新版本的符号链接

 ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python

Close and open a new terminal关闭并打开一个新终端

and try并尝试

 python --version

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:这将 output 是这样的:

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).您现在可以 select 您将取消链接(删除)哪些包。

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).重要提示:从 Lion 开始,--unlink 不再可用(截至 2014 年第一季度,包括 Lion、Mountain Lion 和 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如果阅读本说明的任何人尝试将其与 lion 一起使用,则应尝试根据这篇文章的内容对其进行调整: https://wincent.com/wiki/Uninstalling_packages_(.pkg_files)_on_Mac_OS_X

Trying to uninstall Python with尝试卸载 Python

brew uninstall python

will not remove the natively installed Python but rather the version installed with brew .不会删除本机安装的 Python 而是使用brew安装的版本。

No need to uninstall it or going crazy with symbolic links, just use an alias .无需卸载它或疯狂使用符号链接,只需使用alias即可。 I faced the same problem when upgrading to python 3.7.1.升级到 python 3.7.1 时,我遇到了同样的问题。
Just install the new python version using brew install python then in your .bash_profile create an alias pointing to the new python version;只需使用brew install python安装新的 python 版本,然后在您的.bash_profile中创建一个指向新的 python 版本的别名; like this: alias python="/usr/local/bin/python3" then save and run source ~/.bash_profile .像这样: alias python="/usr/local/bin/python3"然后保存并运行source ~/.bash_profile
Done.完毕。

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

I faced the same problem when upgrading to python 3.9 from python 2.7.16 Just install the new python version using brew install python or download and install for your OS then从 python 2.7.16 升级到 python 3.9 时,我遇到了同样的问题 只需使用 brew install python 安装新的 python 版本,或者为您的操作系统下载并安装

  1. sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
  2.  sudo rm -rf "/Applications/Python 2.7"
  3.  ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7'
  4. then check -> python --version然后检查 -> python --version

  5. in your .bash_profile create an alias pointing to the new python version;在您的.bash_profile中创建一个指向新版本 python 的别名; like this:像这样:

     alias python="/usr/local/bin/python3"

    then save and run source ~/.bash_profile .然后保存并运行 source ~/.bash_profile

  6. check -> python --version检查 -> python --version

all set now一切就绪

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

Onur Güzel provides the solution in his blog post, "Uninstall Python Package from OS X . Onur Güzel 在他的博客文章“从 OS X 卸载 Python Package”中提供了解决方案。

You should type the following commands into the terminal:您应该在终端中输入以下命令:

  1. sudo rm -rf /Library/Frameworks/Python.framework

  2. cd /usr/local/bin

  3. ls -l. | grep '../Library/Frameworks/Python.framework' | awk '{print $9}' | xargs sudo rm

  4. sudo rm -rf "/Applications/Python xy"

    where command xy is the version of Python installed.其中命令 xy 是安装的 Python 的版本。 According to your question, it should be 2.7.根据你的问题,应该是2.7。

In Onur's words:用奥努尔的话来说:

WARNING: This commands will remove all Python versions installed with packages.警告:此命令将删除随软件包安装的所有 Python 版本。 Python provided from the system will not be affected.系统提供的Python不受影响。

If you have more than 1 Python version installed from python.org, then run the fourth command again, changing "xy" for each version of Python that is to be uninstalled.如果您从 python.org 安装了超过 1 个 Python 版本,则再次运行第四条命令,为每个要卸载的 Python 版本更改“xy”。

This is what worked for me on Mac OS这就是我在 Mac OS 上的工作方式

  1. Download the latest Python 3.x from https://www.python.org/downloads/mac-osx/https 下载最新的 Python 3.x://www.python.org/downloads/mac-osx/

  2. Install Python 3.x by going through the Installation Steps that show up when you click on the installer通过单击安装程序时显示的安装步骤安装 Python 3.x

  3. ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

  4. ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip

  5. Open a new terminal window and verify python --version .打开一个新终端 window 并验证python --version Should say 3.x应该说 3.x

For step 3, confirm the path for your existing python executable by checking the output of which python对于第 3 步,通过检查 output which python来确认现有 python 可执行文件的路径

On a MacOS where python3 was installed with brew :在使用brew安装了python3的 MacOS 上:

sudo ln -s -f /opt/homebrew/bin/python3 /usr/local/bin/python
sudo ln -s -f /opt/homebrew/bin/pip3 /usr/local/bin/pip

Reopen terminal重新打开终端

python --version
pip --version

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

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 Apple 将在 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:实际上,根据The 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.鉴于这一启示,我建议最好的行动方案是什么都不做,等待 Apple 为您擦除它。 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 人来说,这个问题似乎已经成为一个支点,无论他们运行的是什么版本。

Caution when trying to remove certain python library, Mac OS needs python: DO NOT remove any Python versions in the following folders:尝试删除某些 python 库时要小心,Mac OS 需要 python:请勿删除以下文件夹中的任何 Python 版本:

/usr/bin
system/Library

These Python 2.7 versions are installed by Apple and used by Mac OS and other software.这些 Python 2.7 版本由 Apple 安装并供 Mac OS 和其他软件使用。 Deleting Python from these directories can break your system.从这些目录中删除 Python 可能会破坏您的系统。

Here you will see all the preinstalled versions of python including 2.3, 2.4 and even 2.7.在这里您将看到 python 的所有预装版本,包括 2.3、2.4 甚至 2.7。

/System/Library/Frameworks/Python.framework/Versions

But, even with sudo I do not think so, you will be able to remove them.但是,即使使用 sudo 我也不这么认为,你将能够删除它们。 You will get an error - Operation not permitted你会得到一个错误 - Operation not permitted

Install the new python version using brew install python In.bash_profile or.zprofile create an alias like this: alias python="/usr/local/bin/python3" Done.安装新的 python 版本使用 brew install python 在.bash_profile 或.zprofile 中创建一个像这样的别名:alias python="/usr/local/bin/python3" 完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM