如何在MacOSX10.6.4上卸载Python2.7?

2024-06-16 10:06:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从MacOSX10.6.4中完全删除Python2.7。我通过还原我的.bash_profile,成功地从PATH变量中删除了该项。但是我还想删除Python 2.7安装包安装的所有目录、文件、符号链接和条目。我从http://www.python.org/获得了安装包。我需要删除哪些目录/文件/配置文件条目?有单子吗?


Tags: 文件pathorg目录bashhttp链接www
3条回答

这个有效:

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

说明: 它列出所有链接,删除@字符,然后删除它们。

如果使用PKG安装程序安装,则可以执行以下操作:

pkgutil --pkgs

或者更好:

pkgutil --pkgs | grep org.python.Python

它将输出如下内容:

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

现在可以选择要取消链接(删除)的包。

这是取消链接文档:

 --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.

在我的示例中,您将键入

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

或一行:

pkgutil --pkgs | grep org.python.Python | xargs -L1 pkgutil -f --unlink

重要提示:从Lion开始,unlink不再可用(从2014年第一季度起,将包括Lion、Mountain Lion和Mavericks)。如果任何人来这里的指示尝试使用它与狮子,应该尝试改为这篇文章所说的:https://wincent.com/wiki/Uninstalling_packages_(.pkg_files)_on_Mac_OS_X

不要试图删除任何苹果提供的系统Python,它们位于/System/Library/usr/bin中,因为这可能会破坏整个操作系统。


注意:下面列出的步骤不会影响Apple提供的系统Python2.7;它们只删除第三方Python框架,就像python.org installers安装的那样。


完整的列表是documented here。基本上,你需要做的就是:

  1. 删除第三方Python2.7框架

    sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
    
  2. 删除Python2.7应用程序目录

    sudo rm -rf "/Applications/Python 2.7"
    
  3. /usr/local/bin中删除指向此Python版本的符号链接。看他们用

    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 $9}' | tr -d @ | xargs rm
    
  4. 如有必要,请编辑shell配置文件以删除将/Library/Frameworks/Python.framework/Versions/2.7添加到PATH环境文件中的操作。根据您使用的shell,可能修改了以下任何文件: ~/.bash_login~/.bash_profile~/.cshrc~/.profile~/.tcshrc,和/或~/.zprofile

相关问题 更多 >