如何删除使用 distutils 安装的程序?

发布于 2024-09-28 21:57:15 字数 1010 浏览 6 评论 0原文

我已经使用此 setup.py 安装了一个 python 应用程序:

#!/usr/bin/env python

from distutils.core import setup
from libyouandme import APP_NAME, APP_DESCRIPTION, APP_VERSION, APP_AUTHORS, APP_HOMEPAGE, APP_LICENSE

setup(
    name=APP_NAME.replace(" ","-").lower(),
    version=APP_VERSION,
    description=APP_DESCRIPTION,
    author="John G",
    author_email="[email protected]",
    url=APP_HOMEPAGE,
    license=APP_LICENSE,
    scripts=["youandme.py"],
    packages=["libyouandme"],
    data_files=[
        ('share/applications', ['youandme.desktop']),
        ('usr/share/icons/hicolor/16x16/apps', ['icons/hicolor/16x16/apps/you.png']),
        ('usr/share/icons/hicolor/22x22/apps', ['icons/hicolor/22x22/apps/you.png']),
        ('usr/share/icons/hicolor/48x48/apps', ['icons/hicolor/48x48/apps/you.png'])],
)

如何从我的 ubuntu 计算机中删除此应用程序?

我可以用 distutils 做到这一点吗?

I have installed a python application with this setup.py:

#!/usr/bin/env python

from distutils.core import setup
from libyouandme import APP_NAME, APP_DESCRIPTION, APP_VERSION, APP_AUTHORS, APP_HOMEPAGE, APP_LICENSE

setup(
    name=APP_NAME.replace(" ","-").lower(),
    version=APP_VERSION,
    description=APP_DESCRIPTION,
    author="John G",
    author_email="[email protected]",
    url=APP_HOMEPAGE,
    license=APP_LICENSE,
    scripts=["youandme.py"],
    packages=["libyouandme"],
    data_files=[
        ('share/applications', ['youandme.desktop']),
        ('usr/share/icons/hicolor/16x16/apps', ['icons/hicolor/16x16/apps/you.png']),
        ('usr/share/icons/hicolor/22x22/apps', ['icons/hicolor/22x22/apps/you.png']),
        ('usr/share/icons/hicolor/48x48/apps', ['icons/hicolor/48x48/apps/you.png'])],
)

How can I remove this application from my ubuntu machine ?

Do I can do this with distutils ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风筝在阴天搁浅。 2024-10-05 21:57:15

安装 checkinstall Ubuntu 软件包。 checkinstall 监视安装过程并创建 deb 包。这使您可以使用常规包管理命令来删除软件。

首先,使用 checkinstall 重新安装候选 python 模块/包。将目录更改为包含候选 python 模块/包的 setup.py 文件的目录:

cd <PACKAGE_NAME>

然后:

sudo checkinstall -D --fstrans=no python setup.py install

这将创建一个 .deb 包,并再次安装 python 模块。
系统会问您几个问题。默认答案应该没问题。
(但是,当 setup.py 文件位于 python 模块的子目录(例如“source”子目录)中时,您可以更改 .deb 包的“名称”。)

(保存的 .deb 包现在捕获 python 如何包自行安装,dpkg可以删除python包。)

然后立即删除模块:

sudo dpkg -r <PACKAGE_NAME>

PS。我听说某些安装程序与 checkinstall 不兼容,但我自己从未遇到过任何问题。

Install the checkinstall Ubuntu package. checkinstall monitors the installation procedure and creates a deb package. This lets you use regular package management commands to remove the software.

First, reinstall the candidate python module/package using checkinstall. Change directory to the directory containing the setup.py file of the candidate python module/package:

cd <PACKAGE_NAME>

Then:

sudo checkinstall -D --fstrans=no python setup.py install

This creates a .deb package, and installs the python module again.
You'll be asked a few questions. The default answers should be fine.
(But you might change the "name" of the .deb package, when the setup.py file is in a subdirectory of the python module, for example the "source" subdirectory.)

(The saved .deb package now captures how the python package installed itself, and dpkg can remove the python package.)

Then immediately remove the module:

sudo dpkg -r <PACKAGE_NAME>

PS. I've heard that some installation programs are not compatible with checkinstall, though I've never run into any problems myself.

昔梦 2024-10-05 21:57:15

AFAIK 只有 pip 允许卸载 python 模块,所以如果你没有安装它,你可以安装它

sudo easy_install pip

,然后使用 pip 卸载你的模块,

sudo pip uninstall <module_name>

其中 module_name中传递的值setup 函数的 name 参数。

编辑:刚刚看到您用“python-3.x”标记了您的问题,并且 pip 还没有 3.x 版本,所以如果您需要卸载 python3.x 模块,这个答案不适合。

AFAIK only pip allows to uninstall python modules, so if you don't have it installed, you can install it with

sudo easy_install pip

and then use pip to uninstall your module

sudo pip uninstall <module_name>

where module_name is the value passed in the name argument of the setup function.

Edit: just saw you tagged your question with "python-3.x", and there is no 3.x version for pip yet, so if you need to uninstall a python3.x module, this answer doesn't fit.

九命猫 2024-10-05 21:57:15

由于 pip 8.0.0 运行 pip uninstall 时,当 是操作系统预安装的东西时(可能使用 python setup.json),它不起作用。 py 安装)。

错误信息是:

检测到已安装的 distutils 项目(“”),我们无法卸载该项目。 distutils 提供的元数据不包含已安装的文件列表,因此 pip 不知道要卸载哪些文件。

您需要使用操作系统包管理器,而不是使用 pip 卸载这些包。

因此在 Ubuntu 上:sudo apt-get remove python- 将删除它。

我发现两个有这个问题的包:httplib2six,上面的技巧帮助我解决了这个错误。希望其他人觉得这很有用。

Since pip 8.0.0 running pip uninstall <package> does not work when <package> is something that was pre-installed by the OS (probably with python setup.py install).

The error message is:

Detected a distutils installed project ('<package>') which we cannot uninstall. The metadata provided by distutils does not contain a list of files which have been installed, so pip does not know which files to uninstall.

Instead of using pip to uninstall these packages you need to use the OS package manager instead.

So on Ubuntu: sudo apt-get remove python-<package> would remove it.

I've found two packages that have this problem: httplib2 and six, and the above trick helped me get by that error. Hope that others find this useful.

初与友歌 2024-10-05 21:57:15

disutils 版本 1 不支持卸载命令,我还在评论中添加了一个链接供您查看,但仅供参考 disutils2 现在支持卸载命令,他们在过去的 GSoC 中一直在研究它,您可以检查这个链接

的唯一方法你要“卸载”你的包是通过手动删除所有文件,我可以看到你在 /usr/share 中有一些文件..,我不知道你是否已经知道这一点,但你可以使用 python install.py当开发你的模块时,它会很容易地进行更改和删除。

The disutils version 1 don't support uninstall command and i have also included a link for you in the comment to see it, but just for info disutils2 now support uninstall command , they have been working on it in the past GSoC, you can check this link

The only way for you to "uninstall" your package is by removing all your file by hand, i can see that you have some files in /usr/share .. , i don't know if you know this already but you can use python install.py develop when developing your module , it will make change and remove easily .

落叶缤纷 2024-10-05 21:57:15

我发现在安装新版本的库时,distutils 不会删除不再属于包的旧模块。它只是替换了旧的。这是一个简单的示例,说明我如何在运行安装程序之前卸载旧文件。它本身并不是一个完整和完美的卸载,但它可能会帮助那些有相同需求的人,或者为您提供一个功能性的解决方法。

from distutils.core import setup
import distutils.sysconfig
from os import path
from shutil import rmtree

PACKAGE_NAME = "MyPackage"

# If found, uninstall a prior version.
# This will delete any modules that are no longer in use.
targetDirPath = path.join( distutils.sysconfig.get_python_lib(), PACKAGE_NAME )
if path.exists( targetDirPath ) :
    try :
        rmtree( targetDirPath )
        print "Removed prior package at: %s" % (targetDirPath,)
    except Exception as e:    
        print "Failed to remove prior package at: %s" % (targetDirPath,)
        print e

setup(name=PACKAGE_NAME,
      version='1.2.3',
      packages=['subpackage'] )

I discovered that when installing a new version of a library, distutils did not delete old modules that were no longer part of the package. It only replaced the old ones. Here's a simple example of how I uninstalled the old files before running setup. It's not a complete and perfect uninstall per se, but it might help those of you with the same needs, or send you down a functional workaround path.

from distutils.core import setup
import distutils.sysconfig
from os import path
from shutil import rmtree

PACKAGE_NAME = "MyPackage"

# If found, uninstall a prior version.
# This will delete any modules that are no longer in use.
targetDirPath = path.join( distutils.sysconfig.get_python_lib(), PACKAGE_NAME )
if path.exists( targetDirPath ) :
    try :
        rmtree( targetDirPath )
        print "Removed prior package at: %s" % (targetDirPath,)
    except Exception as e:    
        print "Failed to remove prior package at: %s" % (targetDirPath,)
        print e

setup(name=PACKAGE_NAME,
      version='1.2.3',
      packages=['subpackage'] )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文