问题:python setup.py卸载

我已经使用安装了python软件包python setup.py install

如何卸载?

I have installed a python package with python setup.py install.

How do I uninstall it?


回答 0

注意:避免python setup.py install使用pip install .

您需要手动删除所有文件,还需要撤消安装过程中手动执行的任何其他操作。

如果您不知道所有文件的列表,则可以使用--record选件重新安装它,然后查看生成的列表。

要记录已安装文件的列表,可以使用:

python setup.py install --record files.txt

想要卸载后,可以使用xargs进行删除:

xargs rm -rf < files.txt

或者,如果您正在运行Windows,请使用Powershell:

Get-Content files.txt | ForEach-Object {Remove-Item $_ -Recurse -Force}

然后也删除包含的目录,例如/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/my_module-0.1.egg/on macOS。它没有文件,但是Python仍将导入一个空模块:

>>> import my_module
>>> my_module.__file__
None

删除后,Python将显示:

>>> import my_module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'my_module'

Note: Avoid using python setup.py install use pip install .

You need to remove all files manually, and also undo any other stuff that installation did manually.

If you don’t know the list of all files, you can reinstall it with the --record option, and take a look at the list this produces.

To record a list of installed files, you can use:

python setup.py install --record files.txt

Once you want to uninstall you can use xargs to do the removal:

xargs rm -rf < files.txt

Or if you’re running Windows, use Powershell:

Get-Content files.txt | ForEach-Object {Remove-Item $_ -Recurse -Force}

Then delete also the containing directory, e.g. /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/my_module-0.1.egg/ on macOS. It has no files, but Python will still import an empty module:

>>> import my_module
>>> my_module.__file__
None

Once deleted, Python shows:

>>> import my_module
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'my_module'

回答 1

对我来说,以下主要工作方式:

已安装点子,例如:

$ easy_install pip

从pip的角度检查已安装的软件包的名称:

$ pip freeze

这将列出您已经安装(并且被pip检测到)的所有软件包的名称。该名称可能会很长,然后仅使用和之后显示的程序包的名称#egg=。在大多数情况下,您也可以忽略版本部分(无论是后面的==还是-)。

然后卸载该软件包:

$ pip uninstall package.name.you.have.found

如果它要求您确认删除软件包,那么您很幸运,它将被删除。

pip应检测所有由pip安装的软件包。它还应检测通过easy_install或setup.py安装的大多数软件包,但这在极少数情况下可能会失败。

这是来自本地测试的真实示例,带有ttr.rdstmc在Windows上命名的软件包。

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev

$ python setup.py develop
.....
.....
Finished processing dependencies for ttr.rdstmc==0.0.1dev

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
-e hg+https://vlcinsky@bitbucket.org/vlcinsky/ttr.rdstmc@d61a9922920c508862602f7f39e496f7b99315f0#egg=ttr.rdstmc-dev
ttr.utcutils==0.1.1dev

$ pip uninstall ttr.rdstmc
Uninstalling ttr.rdstmc:
  c:\python27\lib\site-packages\ttr.rdstmc.egg-link
Proceed (y/n)? y
  Successfully uninstalled ttr.rdstmc

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev

编辑2015-05-20

上面写的所有内容仍然适用,无论如何,现在有一些小的修改。

在python 2.7.9和python 3.4中安装pip

最新的python版本附带了一个软件包ensurepip,即使离线也可以安装pip:

$ python -m surepip-升级

在某些系统(例如Debian Jessie)上,此功能不可用(以防止破坏系统python安装)。

使用grepfind

上面的示例假定您已grep安装。我(当时我的计算机上装有MS Windows)安装了一套Linux实用程序(包括grep)。或者,使用本机MS Windows find或简单地忽略该过滤,并在更长的检测到的python软件包列表中找到名称。

For me, the following mostly works:

have pip installed, e.g.:

$ easy_install pip

Check, how is your installed package named from pip point of view:

$ pip freeze

This shall list names of all packages, you have installed (and which were detected by pip). The name can be sometime long, then use just the name of the package being shown at the and after #egg=. You can also in most cases ignore the version part (whatever follows == or -).

Then uninstall the package:

$ pip uninstall package.name.you.have.found

If it asks for confirmation about removing the package, then you are lucky guy and it will be removed.

pip shall detect all packages, which were installed by pip. It shall also detect most of the packages installed via easy_install or setup.py, but this may in some rare cases fail.

Here is real sample from my local test with package named ttr.rdstmc on MS Windows.

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev

$ python setup.py develop
.....
.....
Finished processing dependencies for ttr.rdstmc==0.0.1dev

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
-e hg+https://vlcinsky@bitbucket.org/vlcinsky/ttr.rdstmc@d61a9922920c508862602f7f39e496f7b99315f0#egg=ttr.rdstmc-dev
ttr.utcutils==0.1.1dev

$ pip uninstall ttr.rdstmc
Uninstalling ttr.rdstmc:
  c:\python27\lib\site-packages\ttr.rdstmc.egg-link
Proceed (y/n)? y
  Successfully uninstalled ttr.rdstmc

$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev

Edit 2015-05-20

All what is written above still applies, anyway, there are small modifications available now.

Install pip in python 2.7.9 and python 3.4

Recent python versions come with a package ensurepip allowing to install pip even when being offline:

$ python -m ensurepip –upgrade

On some systems (like Debian Jessie) this is not available (to prevent breaking system python installation).

Using grep or find

Examples above assume, you have grep installed. I had (at the time I had MS Windows on my machine) installed set of linux utilities (incl. grep). Alternatively, use native MS Windows find or simply ignore that filtering and find the name in a bit longer list of detected python packages.


回答 2

第一个答案有问题:

  • 在Mac上无法使用。
  • 如果安装的文件包含空格或其他特殊字符,该xargs命令将失败,并删除与各个单词匹配的所有文件/目录。
  • -rrm -rf是不必要的,在最坏的情况可能会删除你不想要的东西。

相反,对于类Unix:

sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --

对于Windows:

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

卸载setup.py安装还有一些无法解决的问题,在典型情况下不会打扰您。有关更完整的答案,请参见以下Wiki页面:

https://ofswiki.org/wiki/Uninstalling_setup.py_install

The #1 answer has problems:

  • Won’t work on mac.
  • If a file is installed which includes spaces or other special characters, the xargs command will fail, and delete any files/directories which matched the individual words.
  • the -r in rm -rf is unnecessary and at worst could delete things you don’t want to.

Instead, for unix-like:

sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --

And for windows:

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

There are also unsolvable problems with uninstalling setup.py install which won’t bother you in a typical case. For a more complete answer, see this wiki page:

https://ofswiki.org/wiki/Uninstalling_setup.py_install


回答 3

首先记录您已安装的文件。即使您先前已经运行过,也可以重复此命令setup.py install

python setup.py install --record files.txt

要卸载时,您可以:

sudo rm $(cat files.txt)

之所以可行,是因为rm命令使用空格分隔的文件列表来删除,并且您的安装记录就是这样的列表。

First record the files you have installed. You can repeat this command, even if you have previously run setup.py install:

python setup.py install --record files.txt

When you want to uninstall you can just:

sudo rm $(cat files.txt)

This works because the rm command takes a whitespace-seperated list of files to delete and your installation record is just such a list.


回答 4

现在,python让您可以选择在安装pip过程中进行安装(我在Windows上,至少python在Windows上可以!)。考虑到您已选择pip在安装python时进行安装(实际上是默认设置,因此不必选择),pip已经为您安装了。然后,pip在命令提示符下键入,您应该会看到一个帮助。您可以在此处找到必要的使用说明。例如,pip list显示已安装软件包的列表。您可以使用

pip uninstall package_name

卸载不再需要的任何软件包。在此处阅读更多信息(pip文档)

Now python gives you the choice to install pip during the installation (I am on Windows, and at least python does so for Windows!). Considering you had chosen to install pip during installation of python (you don’t actually have to choose because it is default), pip is already installed for you. Then, type in pip in command prompt, you should see a help come up. You can find necessary usage instructions there. E.g. pip list shows you the list of installed packages. You can use

pip uninstall package_name

to uninstall any package that you don’t want anymore. Read more here (pip documentation).


回答 5

懒惰的方式:只需从Windows安装菜单(如果使用Windows)或从rpm命令卸载,前提是您在创建分发程序包后首先重新安装它。

例如,

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

(“ foo”当然是示例)。

The lazy way: simply uninstall from the Windows installation menu (if you’re using Windows), or from the rpm command, provided you first re-install it after creating a distribution package.

For example,

python setup.py bdist_wininst
dist/foo-1.0.win32.exe

(“foo” being an example of course).


回答 6

转到python软件包目录并删除.egg文件,例如:在python 2.5(ubuntu)中:/usr/lib/python2.5/site-packages/

在python 2.6(ubuntu)中:/usr/local/lib/python2.6/dist-packages/

Go to your python package directory and remove your .egg file, e.g.: In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/

In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/


回答 7

不能完全回答问题,但每天都能对我有所帮助:

安装您的软件包

pip install .

这会将包装放入$HOME/.local。卸载

pip uninstall <package_name>

Not exactly answering the question, but something that helps me every day:

Install your packages with

pip install .

This puts the package in $HOME/.local. Uninstall with

pip uninstall <package_name>

回答 8

可能您可以这样做:

1)获取python版本-

[linux machine]# python
Python 2.4.3 (#1, Jun 18 2012, 14:38:55) 

->上面的命令为您提供了当前的python版本2.4.3

2)获取python的安装目录-

[linux machine]# whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.5 /usr/include/python2.4 /usr/share/man/man1/python.1.gz

->从上面的命令中,您可以获得安装目录-/ usr/lib/python2.4/sitepackages

3)从这里您可以删除软件包和python egg文件

[linux machine]# cd /usr/lib/python2.4/site-packages
[linux machine]# rm -rf paramiko-1.12.0-py2.4.egg paramiko-1.7.7.1-py2.4.egg paramiko-1.9.0-py2.4.egg

这对我有用。而且我能够卸载困扰我的软件包:)

Probably you can do this as an alternative :-

1) Get the python version –

[linux machine]# python
Python 2.4.3 (#1, Jun 18 2012, 14:38:55) 

-> The above command gives you the current python Version which is 2.4.3

2) Get the installation directory of python –

[linux machine]# whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.5 /usr/include/python2.4 /usr/share/man/man1/python.1.gz

-> From above command you can get the installation directory which is – /usr/lib/python2.4/site-packages

3) From here you can remove the packages and python egg files

[linux machine]# cd /usr/lib/python2.4/site-packages
[linux machine]# rm -rf paramiko-1.12.0-py2.4.egg paramiko-1.7.7.1-py2.4.egg paramiko-1.9.0-py2.4.egg

This worked for me.. And i was able to uninstall package which was troubling me :)


回答 9

我认为您可以打开setup.py,找到软件包名称,然后要求pip卸载它。

假设名称在“ METADATA”变量中可用:

pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")

I think you can open the setup.py, locate the package name, and then ask pip to uninstall it.

Assuming the name is available in a ‘METADATA’ variable:

pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")

回答 10

扩展一下Martin所说的内容,记录安装输出和一些bash脚本就可以很好地解决问题。这是我的工作

for i in $(less install.record);
sudo rm $i;
done;

和presto。已卸载。

Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here’s what I do…

for i in $(less install.record);
sudo rm $i;
done;

And presto. Uninstalled.


回答 11

如果在重新安装软件包后仍有一些文件应删除,请确保该文件夹build也已删除。因此,假设这pkg是您要删除的软件包:

rm -r $(python3 -c "import pkg; print(pkg.__path__[0] + '*' )") 
rm -rf build

以上为python3计算并删除了软件包及其* .egg-info文件

If you still have files that are supposed to be deleted after re-installing a package, make sure the folder build is also deleted. Therefore, assuming that pkg is the package you want to delete:

rm -r $(python3 -c "import pkg; print(pkg.__path__[0] + '*' )") 
rm -rf build

Obove work out for python3 and delete the package and its *.egg-info file


回答 12

{virtualenv}/lib/python2.7/site-packages/(如果未使用virtualenv,则为{system_dir}/lib/python2.7/dist-packages/

  • 删除鸡蛋文件(例如distribute-0.6.34-py2.7.egg
  • 如果文件中有任何内容easy-install.pth,请删除相应的行(它应该是源目录或egg文件的路径)。

At {virtualenv}/lib/python2.7/site-packages/ (if not using virtualenv then {system_dir}/lib/python2.7/dist-packages/)

  • Remove the egg file (e.g. distribute-0.6.34-py2.7.egg)
  • If there is any from file easy-install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).

回答 13

我过去曾经在全局环境中偶然运行过“ python setup.py install”,并且卸载时遇到很多困难。这些解决方案没有帮助。“ pip卸载”不适用于“无法卸载’splunk-appinspect’。找不到要卸载的文件。” “ sudo pip卸载”不起作用“无法卸载要求splunk-appinspect,未安装”。我尝试卸载pip,删除pip缓存,在硬盘上搜索该软件包等,…

“ pip show”最终将我引向解决方案,“ Location:”指向目录,并且重命名该目录导致打包的内容从pip列表中删除。我重命名了目录,但它没有重新出现在pip的列表中,现在我可以在virtualenv中重新安装我的软件包了。

I had run “python setup.py install” at some point in the past accidentally in my global environment, and had much difficulty uninstalling. These solutions didn’t help. “pip uninstall ” didn’t work with “Can’t uninstall ‘splunk-appinspect’. No files were found to uninstall.” “sudo pip uninstall ” didn’t work “Cannot uninstall requirement splunk-appinspect, not installed”. I tried uninstalling pip, deleting the pip cache, searching my hard drive for the package, etc…

“pip show ” eventually led me to the solution, the “Location:” was pointing to a directory, and renaming that directory caused the packaged to be removed from pip’s list. I renamed the directory back, and it didn’t reappear in pip’s list, and now I can reinstall my package in a virtualenv.


回答 14

python setup.py install在PyCharm中运行了一次,它将所有软件包安装到conda基本环境中。以后,当我要删除所有这些程序包时,将pip uninstall无法正常工作。我不得不从/anaconda3/lib/python3.7/site-packages中手动删除它们:(

因此,我看不出他们为什么使用setup.py而不是编写requirements.txt文件的原因。需求文件可用于在虚拟环境中安装软件包,并且不会与系统python软件包混淆。

I had run python setup.py install once in my PyCharm, it installs all the packages into my conda base environment. Later when I want to remove all these packages, pip uninstall does not work. I had to delete them from /anaconda3/lib/python3.7/site-packages manually :(

So I don’t see the reason why they use setup.py instead of writing requirements.txt file. The requirement file can be used to install packages in virtual environment and won’t mess with system python packages.


回答 15

最好使用bash读取命令来删除相关文件,如下所示:

sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"

It might be better to remove related files by using bash to read commands, like the following:

sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。