如何在 mac os x 上找到所有 python 安装并卸载除本机 OS X 安装之外的所有安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25840961/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:43:31  来源:igfitidea点击:

How to find all python installations on mac os x and uninstall all but the native OS X installation

pythonmacosunixpip

提问by Ishaan Taylor

I have installed a few versions on my MacBook for different projects and have only now realized what a mistake that was. I have used homebrew to install it, installed it via python's website (Python 2.7.8 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and later [2])) and other ways I may not remember. I am running 10.9.4 OS X.

我已经在我的 MacBook 上为不同的项目安装了几个版本,现在才意识到这是一个多么大的错误。我使用自制软件安装它,通过python的网站(Python 2.7.8 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and later [2]))和其他我可能不记得的方式安装它。我正在运行 10.9.4 OS X。

I am wondering how I can find the location of all python installations on my computer and delete everything and packages that depend on them exceptthe native one.I'd like to essentially start from scratch without reinstalling my OS.

我想知道如何在我的计算机上找到所有 python 安装的位置,并删除依赖它们的所有内容和包,除了本机的包。我想基本上从头开始而不重新安装我的操作系统。

Also, I am wondering if I can apply the same method to find all piprelated files.

另外,我想知道是否可以应用相同的方法来查找所有pip相关文件。

Update:

更新

which -a pythongives me all the paths to each executable python. Is it normal to have multiple ones?

which -a python给了我每个可执行 python 的所有路径。有多个是正常的吗?

╭─[email protected] ~
╰─?  which -a python
/usr/bin/python
/usr/bin/python
/usr/bin/python
/usr/bin/python
/usr/bin/python
/usr/bin//python
/usr/bin//python
/usr/bin/python

回答by Brad Allred

you can start by removing any Python Frameworks in /Library/Frameworksand any User Library (like ~/Library/Frameworks). The system one is in /System/Library/Frameworks.

您可以首先删除任何 Python 框架/Library/Frameworks和任何用户库(如~/Library/Frameworks)。系统一在/System/Library/Frameworks

homebrew and macports install under /usrsomewhere IIRC. not sure of other places to look, but you should be able to grep for "Python" to find them all.

homebrew 和 macports 安装在/usr某处 IIRC 下。不确定其他地方可以查看,但您应该能够使用 grep 查找“Python”以找到所有这些地方。

be aware, if you have installed othersoftware via homebrew that is dependent on Python, you will break it. you may be able to fix it with symbolic links to the system python, however, some software requires Python 3. as of 10.9 the system has Python 2.3-2.7 only.

请注意,如果您通过依赖 Python 的自制软件安装了其他软件,您将破坏它。您可以使用指向系统 python 的符号链接来修复它,但是,某些软件需要 Python 3。从 10.9 开始,系统仅具有 Python 2.3-2.7。

回答by Yury Kirienko

It's normal to have many pythonbinaries. You can see which is which in /usr/binwith this command:

有很多python二进制文件是正常的。您可以/usr/bin使用此命令查看哪个是哪个:

$ ls -l /usr/bin/python*

$ ls -l /usr/bin/python*

You will see several links to different places. The nativepythonis that one, which is in the /System/Library/Frameworks/Python.framework/Versions/2.7/bin/. Note that for OSX 10.9 (and for everything at least until 10.13) this is the python2, not python3. So you can safely remove all the other versions.

您将看到几个指向不同地方的链接。本python是那个,它在/System/Library/Frameworks/Python.framework/Versions/2.7/bin/. 请注意,对于OSX 10.9(以及一切至少要等到10.13),这是python2不是python3。因此,您可以安全地删除所有其他版本。

What are the other versions which you may have?

您可能拥有的其他版本是什么?

  • Something downloaded from the official site python.org. It is located in /Library/Frameworks/Python.framework/Versions/. You can remove this.
  • Anacondadistribution is by default located in /Users/your_user/anaconda3/, but of course you may put in the other place. But if it contains anacondain the path – it's Anaconda distribution. You may remove this folder.
  • Either homebrewor portversions are in /opt/local/bin/. See the link destination with $ ln -l /opt/local/bin/python*. The best way of removing this is to use built-in commands like uninstall.
  • Some packages might be in ~/Library/Python/- that's from pip. You may safely remove the entire content of this folder in order to have a "clean"python.
  • Finally, after you removed all the other versions, do not forget to remove the broken links to binaries, if there are still any.
  • 从官方网站python.org下载的东西。它位于/Library/Frameworks/Python.framework/Versions/. 你可以删除这个。
  • Anaconda发行版默认位于/Users/your_user/anaconda3/,但您当然可以放在其他地方。但是如果它包含anaconda在路径中 - 它是 Anaconda 发行版。您可以删除此文件夹。
  • 无论是homebrewport版本都在/opt/local/bin/。用 看到链接目的地$ ln -l /opt/local/bin/python*。删除它的最佳方法是使用诸如卸载之类的内置命令。
  • 一些包可能在~/Library/Python/- 那是从pip. 您可以安全地删除此文件夹的全部内容以获得“干净”的python.
  • 最后,在删除所有其他版本后,不要忘记删除指向二进制文件的损坏链接(如果仍有的话)。

See also this answer.

另请参阅此答案