如何卸载使用distutils安装的python包?

时间:2022-05-05 15:32:52

Can you simply delete the directory from your python installation, or are there any lingering files that you must delete?

您是否可以简单地从python安装中删除该目录,或者是否需要删除任何残留的文件?

11 个解决方案

#1


38  

It varies based on the options that you pass to install and the contents of the distutils configuration files on the system/in the package. I don't believe that any files are modified outside of directories specified in these ways.

它根据您传递给安装的选项以及系统/包中的distutils配置文件的内容而变化。我不相信任何文件都是在这些方式指定的目录之外被修改的。

Notably, distutils does not have an uninstall command at this time.

值得注意的是,distutils此时没有卸载命令。

It's also noteworthy that deleting a package/egg can cause dependency issues -- utilities like easy_install attempt to alleviate such problems.

同样值得注意的是,删除一个包/鸡蛋会导致依赖性问题——像easy_install这样的实用程序试图缓解这些问题。

#2


17  

The three things that get installed that you will need to delete are:

你需要删除的三件事是:

  1. Packages/modules
  2. 包/模块
  3. Scripts
  4. 脚本
  5. Data files
  6. 数据文件

Now on my linux system these live in:

在我的linux系统上

  1. /usr/lib/python2.5/site-packages
  2. /usr/lib/python2.5/site-packages
  3. /usr/bin
  4. 工作
  5. /usr/share
  6. /usr/share

But on a windows system they are more likely to be entirely within the Python distribution directory. I have no idea about OSX except it is more likey to follow the linux pattern.

但在windows系统上,它们更可能完全位于Python分发目录中。我对OSX一无所知,除了它更适合遵循linux模式。

#3


14  

Another time stamp based hack:

另一个基于时间戳的黑客:

  1. Create an anchor: touch /tmp/ts
  2. 创建一个锚点:touch /tmp/ts
  3. Reinstall the package to be removed: python setup.py install --prefix=<PREFIX>
  4. 重新安装要删除的包:python安装。py安装——prefix = <前缀>
  5. Remove files what are more recent than the anchor file: find <PREFIX> -cnewer /tmp/ts | xargs rm -r
  6. 删除比锚文件最近的文件:查找 <前缀> -cnew /tmp/ts | xargs rm -r

#4


7  

Yes, it is safe to simply delete anything that distutils installed. That goes for installed folders or .egg files. Naturally anything that depends on that code will no longer work.

是的,简单地删除distutils安装的任何内容是安全的。这适用于已安装的文件夹或.egg文件。当然,任何依赖于该代码的东西都将不再工作。

If you want to make it work again, simply re-install.

如果你想让它再次工作,只需重新安装。

By the way, if you are using distutils also consider using the multi-version feature. It allows you to have multiple versions of any single package installed. That means you do not need to delete an old version of a package if you simply want to install a newer version.

顺便说一下,如果您使用的是distutils,请考虑使用多版本特性。它允许安装任何单个包的多个版本。这意味着如果您只是想安装一个更新的版本,那么您不需要删除一个旧版本的包。

#5


4  

If this is for testing and/or development purposes, setuptools has a develop command that updates every time you make a change (so you don't have to uninstall and reinstall every time you make a change). And you can uninstall the package using this command as well.

如果这是为了测试和/或开发目的,setuptools有一个开发命令,它在每次进行更改时进行更新(因此您不必在每次进行更改时卸载和重新安装)。您也可以使用这个命令卸载包。

If you do use this, anything that you declare as a script will be left behind as a lingering file.

如果您确实使用了这个,那么您声明为脚本的任何内容都将被保留为一个延迟文件。

#6


4  

In ubuntu 12.04, I have found that the only place you need to look by default is under

在ubuntu 12.04中,我发现唯一需要查看默认值的地方是在下面。

/usr/local/lib/python2.7/

And simply remove the associated folder and file, if there is one!

如果有相关的文件夹和文件,只需删除!

#7


2  

I just uninstalled a python package, and even though I'm not certain I did so perfectly, I'm reasonably confident.

我刚刚卸载了一个python包,尽管我不确定我做得如此完美,但我还是相当有信心。

I started by getting a list of all python-related files, ordered by date, on the assumption that all of the files in my package will have more or less the same timestamp, and no other files will.

我首先得到了一个所有与python相关的文件的列表,按日期顺序排列,假设我的包中的所有文件都或多或少都具有相同的时间戳,并且没有其他文件可以。

Luckily, I've got python installed under /opt/Python-2.6.1; if I had been using the Python that comes with my Linux distro, I'd have had to scour all of /usr, which would have taken a long time.

幸运的是,我在/opt/ python -2.6.1中安装了python;如果我使用的是Linux发行版附带的Python,那么我将不得不搜索/usr,这将花费很长时间。

Then I just examined that list, and noted with relief that all the stuff that I wanted to nuke consisted of one directory, /opt/Python-2.6.1/lib/python2.6/site-packages/module-name/, and one file, /opt/Python-2.6.1/lib/python2.6/site-packages/module-x.x.x_blah-py2.6.egg-info.

然后我检查了这个列表,并如释重负地注意到,我要使用的所有东西都是一个目录,/opt/Python-2.6.1/lib/python2.6/site-packages/module-name/,以及一个文件,/opt/Python-2.6.1/ python2.6/site-packages/module- x.x.x.x.x.x.html -py2.6。

So I just deleted those.

我把它们删掉了。

Here's how I got the date-sorted list of files:

以下是我如何得到日期排序的文件列表:

find "$@" -printf '%T@ ' -ls | sort -n | cut -d\ -f 2-

找到“$ @”printf“% T@”排序- n - ls | | - d \ - f 2 -

(I think that's got to be GNU "find", by the way; the flavor you get on OS X doesn't know about "-printf '%T@'")

(顺便说一句,我想应该是GNU的“查找”;你在OS X上得到的味道不知道“-printf '%T@”)

I use that all the time.

我一直在用它。

#8


2  

For Windows 7,

Windows 7,

Control Panel --> Programs --> Uninstall

控制面板——>程序——>卸载

, then

,然后

choose the python package to remove.

选择要删除的python包。

#9


2  

install --record + xargs rm

安装——记录+ xargs rm

sudo python setup.py install --record files.txt
xargs sudo rm -rf < files.txt

removes all files and but leaves empty directories behind.

删除所有文件,但留下空目录。

That is not ideal, it should be enough to avoid package conflicts.

这并不理想,应该足以避免包装冲突。

And then you can finish the job manually if you want by reading files.txt, or be braver and automate empty directory removal as well.

然后你可以通过读取文件来手动完成这项工作。txt,或者更大胆一些,并自动将空目录删除。

A safe helper would be:

一个安全的帮手应该是:

python-setup-uninstall() (
  sudo rm -f files.txt
  sudo python setup.py install --record files.txt && \
  xargs rm -rf < files.txt
  sudo rm -f files.txt
)

Tested in Python 2.7.6, Ubuntu 14.04.

在Python 2.7.6、Ubuntu 14.04中测试。

#10


1  

for Python in Windows:

Python的窗口:

python -m pip uninstall "package_keyword"
uninstall **** (y/n)?

#11


0  

On Mac OSX, manually delete these 2 directories under your pathToPython/site-packages/ will work:

在Mac OSX上,手动删除pathToPython/站点包/下的这两个目录:

  • {packageName}
  • { packageName }
  • {packageName}-{version}-info
  • { packageName } - { version }信息

for example, to remove pyasn1, which is a distutils installed project:

例如,要删除pyasn1,它是一个已安装的项目:

  • rm -rf lib/python2.7/site-packages/pyasn1
  • rm射频lib / python2.7 /网站/ pyasn1
  • rm -rf lib/python2.7/site-packages/pyasn1-0.1.9-py2.7.egg-info
  • rm射频lib / python2.7 /网站/ pyasn1-0.1.9-py2.7.egg-info

#1


38  

It varies based on the options that you pass to install and the contents of the distutils configuration files on the system/in the package. I don't believe that any files are modified outside of directories specified in these ways.

它根据您传递给安装的选项以及系统/包中的distutils配置文件的内容而变化。我不相信任何文件都是在这些方式指定的目录之外被修改的。

Notably, distutils does not have an uninstall command at this time.

值得注意的是,distutils此时没有卸载命令。

It's also noteworthy that deleting a package/egg can cause dependency issues -- utilities like easy_install attempt to alleviate such problems.

同样值得注意的是,删除一个包/鸡蛋会导致依赖性问题——像easy_install这样的实用程序试图缓解这些问题。

#2


17  

The three things that get installed that you will need to delete are:

你需要删除的三件事是:

  1. Packages/modules
  2. 包/模块
  3. Scripts
  4. 脚本
  5. Data files
  6. 数据文件

Now on my linux system these live in:

在我的linux系统上

  1. /usr/lib/python2.5/site-packages
  2. /usr/lib/python2.5/site-packages
  3. /usr/bin
  4. 工作
  5. /usr/share
  6. /usr/share

But on a windows system they are more likely to be entirely within the Python distribution directory. I have no idea about OSX except it is more likey to follow the linux pattern.

但在windows系统上,它们更可能完全位于Python分发目录中。我对OSX一无所知,除了它更适合遵循linux模式。

#3


14  

Another time stamp based hack:

另一个基于时间戳的黑客:

  1. Create an anchor: touch /tmp/ts
  2. 创建一个锚点:touch /tmp/ts
  3. Reinstall the package to be removed: python setup.py install --prefix=<PREFIX>
  4. 重新安装要删除的包:python安装。py安装——prefix = <前缀>
  5. Remove files what are more recent than the anchor file: find <PREFIX> -cnewer /tmp/ts | xargs rm -r
  6. 删除比锚文件最近的文件:查找 <前缀> -cnew /tmp/ts | xargs rm -r

#4


7  

Yes, it is safe to simply delete anything that distutils installed. That goes for installed folders or .egg files. Naturally anything that depends on that code will no longer work.

是的,简单地删除distutils安装的任何内容是安全的。这适用于已安装的文件夹或.egg文件。当然,任何依赖于该代码的东西都将不再工作。

If you want to make it work again, simply re-install.

如果你想让它再次工作,只需重新安装。

By the way, if you are using distutils also consider using the multi-version feature. It allows you to have multiple versions of any single package installed. That means you do not need to delete an old version of a package if you simply want to install a newer version.

顺便说一下,如果您使用的是distutils,请考虑使用多版本特性。它允许安装任何单个包的多个版本。这意味着如果您只是想安装一个更新的版本,那么您不需要删除一个旧版本的包。

#5


4  

If this is for testing and/or development purposes, setuptools has a develop command that updates every time you make a change (so you don't have to uninstall and reinstall every time you make a change). And you can uninstall the package using this command as well.

如果这是为了测试和/或开发目的,setuptools有一个开发命令,它在每次进行更改时进行更新(因此您不必在每次进行更改时卸载和重新安装)。您也可以使用这个命令卸载包。

If you do use this, anything that you declare as a script will be left behind as a lingering file.

如果您确实使用了这个,那么您声明为脚本的任何内容都将被保留为一个延迟文件。

#6


4  

In ubuntu 12.04, I have found that the only place you need to look by default is under

在ubuntu 12.04中,我发现唯一需要查看默认值的地方是在下面。

/usr/local/lib/python2.7/

And simply remove the associated folder and file, if there is one!

如果有相关的文件夹和文件,只需删除!

#7


2  

I just uninstalled a python package, and even though I'm not certain I did so perfectly, I'm reasonably confident.

我刚刚卸载了一个python包,尽管我不确定我做得如此完美,但我还是相当有信心。

I started by getting a list of all python-related files, ordered by date, on the assumption that all of the files in my package will have more or less the same timestamp, and no other files will.

我首先得到了一个所有与python相关的文件的列表,按日期顺序排列,假设我的包中的所有文件都或多或少都具有相同的时间戳,并且没有其他文件可以。

Luckily, I've got python installed under /opt/Python-2.6.1; if I had been using the Python that comes with my Linux distro, I'd have had to scour all of /usr, which would have taken a long time.

幸运的是,我在/opt/ python -2.6.1中安装了python;如果我使用的是Linux发行版附带的Python,那么我将不得不搜索/usr,这将花费很长时间。

Then I just examined that list, and noted with relief that all the stuff that I wanted to nuke consisted of one directory, /opt/Python-2.6.1/lib/python2.6/site-packages/module-name/, and one file, /opt/Python-2.6.1/lib/python2.6/site-packages/module-x.x.x_blah-py2.6.egg-info.

然后我检查了这个列表,并如释重负地注意到,我要使用的所有东西都是一个目录,/opt/Python-2.6.1/lib/python2.6/site-packages/module-name/,以及一个文件,/opt/Python-2.6.1/ python2.6/site-packages/module- x.x.x.x.x.x.html -py2.6。

So I just deleted those.

我把它们删掉了。

Here's how I got the date-sorted list of files:

以下是我如何得到日期排序的文件列表:

find "$@" -printf '%T@ ' -ls | sort -n | cut -d\ -f 2-

找到“$ @”printf“% T@”排序- n - ls | | - d \ - f 2 -

(I think that's got to be GNU "find", by the way; the flavor you get on OS X doesn't know about "-printf '%T@'")

(顺便说一句,我想应该是GNU的“查找”;你在OS X上得到的味道不知道“-printf '%T@”)

I use that all the time.

我一直在用它。

#8


2  

For Windows 7,

Windows 7,

Control Panel --> Programs --> Uninstall

控制面板——>程序——>卸载

, then

,然后

choose the python package to remove.

选择要删除的python包。

#9


2  

install --record + xargs rm

安装——记录+ xargs rm

sudo python setup.py install --record files.txt
xargs sudo rm -rf < files.txt

removes all files and but leaves empty directories behind.

删除所有文件,但留下空目录。

That is not ideal, it should be enough to avoid package conflicts.

这并不理想,应该足以避免包装冲突。

And then you can finish the job manually if you want by reading files.txt, or be braver and automate empty directory removal as well.

然后你可以通过读取文件来手动完成这项工作。txt,或者更大胆一些,并自动将空目录删除。

A safe helper would be:

一个安全的帮手应该是:

python-setup-uninstall() (
  sudo rm -f files.txt
  sudo python setup.py install --record files.txt && \
  xargs rm -rf < files.txt
  sudo rm -f files.txt
)

Tested in Python 2.7.6, Ubuntu 14.04.

在Python 2.7.6、Ubuntu 14.04中测试。

#10


1  

for Python in Windows:

Python的窗口:

python -m pip uninstall "package_keyword"
uninstall **** (y/n)?

#11


0  

On Mac OSX, manually delete these 2 directories under your pathToPython/site-packages/ will work:

在Mac OSX上,手动删除pathToPython/站点包/下的这两个目录:

  • {packageName}
  • { packageName }
  • {packageName}-{version}-info
  • { packageName } - { version }信息

for example, to remove pyasn1, which is a distutils installed project:

例如,要删除pyasn1,它是一个已安装的项目:

  • rm -rf lib/python2.7/site-packages/pyasn1
  • rm射频lib / python2.7 /网站/ pyasn1
  • rm -rf lib/python2.7/site-packages/pyasn1-0.1.9-py2.7.egg-info
  • rm射频lib / python2.7 /网站/ pyasn1-0.1.9-py2.7.egg-info