99

I was trying the python packaging using setuptools and to test I installed the module in develop mode. i.e

python setup.py develop

This has added my modules directory to sys.path. Now I want to remove the module. Is there any way to do this?

cottontail
  • 10,268
  • 18
  • 50
  • 51
copyninja
  • 1,387
  • 2
  • 10
  • 19
  • 4
    Start using `pip` or other manager with uninstall ability for managing python packages. – Tomasz Wysocki Aug 31 '10 at 06:54
  • 1
    @Tomasz How do you do the equivalent of `python setup.py develop` with `pip`? – akaihola Dec 29 '11 at 09:28
  • 7
    pip install -e . – Tomasz Wysocki Dec 29 '11 at 11:22
  • 11
    'pip' is not the right answer to this question. Installing a project you are developing using 'pip' in order to run or use it means you'll have to reinstall every time you modify the source code. The correct way is the use 'setup.py develop' as the original question states. – Jonathan Hartley Jun 29 '12 at 11:25
  • 6
    @JonathanHartley That's just plain false; pip has an `--editable` (or `-e`) argument that behaves [roughly equivalently to setuptools' `develop`](https://stackoverflow.com/q/30306099/1709587). I thought that perhaps `--editable` was newer than your comment, but nope - a quick search of the pip repo on GitHub turns up references to editables in commits back in 2009. What's more, I see that this was already pointed out by Tomasz Wysocki before you commented! – Mark Amery Jan 07 '18 at 12:37
  • @MarkAmery Right you are, thanks for correcting my silly mistake. – Jonathan Hartley Jan 09 '18 at 03:30
  • Does this answer your question? [How to uninstall editable packages with pip (installed with -e)](https://stackoverflow.com/questions/17346619/how-to-uninstall-editable-packages-with-pip-installed-with-e) – Charlie Parker May 02 '20 at 16:10

3 Answers3

235

Use the --uninstall or -u option to develop, i.e:

python setup.py develop --uninstall

This will remove it from easy-install.pth and delete the .egg-link. The only thing it doesn't do is delete scripts (yet).

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
PJ Eby
  • 8,760
  • 5
  • 23
  • 19
  • 3
    Note that if your development version installed some executables, and you changed them in your `setup.py`, you should manually remove them. – norok2 Aug 02 '16 at 08:26
  • 2
    I run it just as explained, no errors in the output, yet I'm still able to import my development package globally, it seems it hasn't been removed. EDIT: I know why, I had to run it with `--user` option as I did during the installation: `python setup.py develop --uninstall --user` – Marek Jul 30 '17 at 15:05
  • I don't think this is safe as things can change in develop (for example) renaming the module. You need to manually remove everything. – mathtick Mar 03 '19 at 20:08
  • @norok2 what are the manual commands one has to run to remove those executables. As far as I know the above works for certain version of python/pip though I'm not sure which ones. – Charlie Parker May 02 '20 at 16:12
  • 1
    @CharlieParker `rm` or `del` depending on your OS. What I meant is that if you had some executables at the time you installed and then change their names (or remove them) in your `setup.py`, then `setup.py` will not know about them any longer (no matter your `pip` / `python` version and you need to take care of them manually. They are usually located in some `bin` directory on POSIX (read Linuxes, BSDs, MacOS X) systems, can't remember about Win. – norok2 May 02 '20 at 16:55
  • @norok2 but otherwise `pip uninstall pkg` should work right? (in my experience it works even for packages installed in development mode with pip [not conda, for that something else is needed]). – Charlie Parker May 02 '20 at 17:32
18

Edit easy-install.pth in your site-packages directory and remove the line that points to your development version of that package.

Zooko
  • 2,342
  • 1
  • 18
  • 12
  • 1
    Yeah i did exactly this and one more file was there by name package-egg-link or something which I removed and now reference to the module is removed Thanks :) – copyninja Sep 01 '10 at 06:13
  • 10
    "setup.py develop --uninstall" does this for you, see @pjeby's answer – Jonathan Hartley Jun 29 '12 at 11:26
  • 3
    This worked for me when `develop --uninstall` failed because I had split a project into two, and the wrong one remained in the original directory. – Wesley Baugh Mar 14 '13 at 10:13
1

I have had a similar problem to this before. What I did was I loaded up the Python shell, imported the module and then printed its __file__ attribute. From there I would just remove the folder or file that was being associated.

What you may want to look into is using virtualenv this system allows you to create a instance of python separate from your system. Any modules you install or use in this instance are self contained including the version of the module.

I keep all my projects now inside of there own contained virtualenv, which allows me to install and use whatever modules I want without worrying about screwing up modules from other projects.

Tanerax
  • 5,826
  • 5
  • 29
  • 27
  • Well from next time I play with packages I will use this so I won't screw up my system Python. Thanks for the info – copyninja Sep 01 '10 at 06:16