Answers:
它取决于您传递给的选项install以及系统/软件包中distutils配置文件的内容。我不相信会以这些方式在指定目录之外修改任何文件。
值得注意的是,distutils目前没有卸载命令。
还值得注意的是,删除包/蛋可能会导致依赖关系问题,例如easy_install尝试减轻此类问题的实用程序。
另一个基于时间戳的hack:
touch /tmp/tspython setup.py install --prefix=<PREFIX>find <PREFIX> -cnewer /tmp/ts | xargs rm -r| xargs rm -r。我建议手动检查每个文件。在ext4(和其他文件系统)上,这find也会列出所有文件夹。如果您的前缀是/usr,则将要删除/usr/*。
是的,只是删除所有已安装distutils的文件是安全的。这适用于已安装的文件夹或.egg文件。自然,任何依赖于该代码的东西都将不再起作用。
如果您想使其再次运行,只需重新安装即可。
顺便说一句,如果您使用的是distutils,请考虑使用多版本功能。它允许您安装任何单个软件包的多个版本。这意味着,如果您只想安装更新版本,则无需删除软件包的旧版本。
如果这是出于测试和/或开发目的,setuptools具有一个develop命令,该命令会在您进行每次更改时进行更新(因此您不必每次进行更改都卸载并重新安装)。您也可以使用此命令卸载软件包。
如果您确实使用了此功能,则您声明为脚本的所有内容都将作为挥之不去的文件留下。
install --record + xargs rm
sudo python setup.py install --record files.txt
xargs sudo rm -rf < files.txt
删除所有文件,但留空目录。
那不是理想的,应该足以避免程序包冲突。
然后,如果需要,您可以通过阅读手动完成任务files.txt,或者也可以勇敢地自动执行空目录删除操作。
一个安全的助手是:
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
)
已在Python 2.7.6,Ubuntu 14.04中测试。
我只是卸载了一个python软件包,即使我不确定我做得多么完美,我还是有足够的信心。
我首先获得了所有与python相关的文件的列表,按日期排序,并假设我包中的所有文件或多或少都具有相同的时间戳,并且没有其他文件。
幸运的是,我已经在下面安装了python /opt/Python-2.6.1;如果我一直在使用Linux发行版随附的Python,那么我将不得不搜索所有的/usr,这将花费很长时间。
然后,我只是查看了该列表,并放心地指出,我想要删除的所有内容都由一个目录/opt/Python-2.6.1/lib/python2.6/site-packages/module-name/和一个文件组成/opt/Python-2.6.1/lib/python2.6/site-packages/module-x.x.x_blah-py2.6.egg-info。
所以我只是删除了那些。
这是我按日期排序的文件列表的方式:
find "$@" -printf '%T@ ' -ls | sort -n | cut -d\ -f 2-
(顺便说一句,我认为这必须是GNU“查找”;您在OS X上获得的风格不了解“ -printf'%T @'”)
我用所有的时间。
在Mac OSX上,手动删除pathToPython / site-packages /下的这两个目录将起作用:
例如,要删除pyasn1,这是一个distutils安装的项目:
要找出您的站点包在哪里:
python -m site
ERROR: flake8 3.7.9 has requirement pycodestyle<2.6.0,>=2.5.0, but you'll have pycodestyle 2.3.1 which is incompatible.
ERROR: nuscenes-devkit 1.0.8 has requirement motmetrics<=1.1.3, but you'll have motmetrics 1.2.0 which is incompatible.
Installing collected packages: descartes, future, torch, cachetools, torchvision, flake8-import-order, xmltodict, entrypoints, flake8, motmetrics, nuscenes-devkit
Attempting uninstall: torch
Found existing installation: torch 1.0.0
Uninstalling torch-1.0.0:
Successfully uninstalled torch-1.0.0
Attempting uninstall: torchvision
Found existing installation: torchvision 0.2.1
Uninstalling torchvision-0.2.1:
Successfully uninstalled torchvision-0.2.1
Attempting uninstall: entrypoints
Found existing installation: entrypoints 0.2.3
ERROR: Cannot uninstall 'entrypoints'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
然后我输入:
conda uninstall entrypoints
pip install --upgrade pycodestyle
pip install nuscenes-devkit
做完了!