How do you uninstall a python package that was installed using distutils?

前端 未结 12 2342
我在风中等你
我在风中等你 2020-11-30 00:36

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

相关标签:
12条回答
  • 2020-11-30 00:36

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

    /usr/local/lib/python2.7/
    

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

    0 讨论(0)
  • 2020-11-30 00:37

    install --record + 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.

    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.

    0 讨论(0)
  • 2020-11-30 00:39

    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.

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

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

    0 讨论(0)
  • 2020-11-30 00:40

    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.

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

    0 讨论(0)
  • 2020-11-30 00:46

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

    • {packageName}
    • {packageName}-{version}-info

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

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

    To find out where is your site-packages:

    python -m site
    
    0 讨论(0)
  • 2020-11-30 00:54

    for Python in Windows:

    python -m pip uninstall "package_keyword"
    uninstall **** (y/n)?
    
    0 讨论(0)
提交回复
热议问题