445

Two options in setup.py develop and install are confusing me. According to this site, using develop creates a special link to site-packages directory.

People have suggested that I use python setup.py install for a fresh installation and python setup.py develop after any changes have been made to the setup file.

Can anyone shed some light on the usage of these commands?

Nathaniel Jones
  • 939
  • 1
  • 14
  • 25
Netro
  • 7,119
  • 6
  • 40
  • 58
  • if you are looking for an example of how to call `pip install -e` without `.` you can do for example: `pip install -e ~/ultimate-utils/ultimate-utils-proj-src/` where `path/src` is the path to the src of the project where `setup.py` is at. This is a useful related question: https://stackoverflow.com/questions/35064426/when-would-the-e-editable-option-be-useful-with-pip-install – Charlie Parker Aug 31 '21 at 21:27

3 Answers3

647

python setup.py install is used to install (typically third party) packages that you're not going to develop/modify/debug yourself.

For your own stuff, you want to first install your package and then be able to frequently edit the code without having to re-install the package every time — and that is exactly what python setup.py develop does: it installs the package (typically just a source folder) in a way that allows you to conveniently edit your code after it’s installed to the (virtual) environment, and have the changes take effect immediately.


Note: It is highly recommended to use pip install . (regular install) and pip install -e . (developer install) to install packages, as invoking setup.py directly will do the wrong things for many dependencies, such as pull prereleases and incompatible package versions, or make the package hard to uninstall with pip.

Update:

The develop counterpart for the latest python -m build approach is as follows (as per):

enter image description here

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
  • 110
    Erik is right. Also useful to know is that `setup.py develop` comes with an `--uninstall` option for when you're done hacking around. – philadams Dec 18 '13 at 21:57
  • 5
    Last thought here is that another option to `setup.py develop` when hacking on a python package is to use "simple (but explicit) path modification to resolve the package properly" re [Kenneth Reitz](http://kennethreitz.org/repository-structure-and-python/) – philadams Dec 18 '13 at 21:59
  • 5
    I ran into problems using `python setup.py develop` trying to set up Ceilometer for local development. I ended up using `pip install -e PATH` (within a virtualenv) in order to avoid [problems that cropped up via `easy_install`](https://ask.openstack.org/en/question/87376/unable-to-setup-ceilometer-in-develop-mode/). – Joe D'Andrea Jan 13 '16 at 16:24
  • 1
    not sure if this matters, but if I am using python 3 etc, does one have to run `python setup.py develop` differently? – Charlie Parker Jan 11 '17 at 01:03
  • @CharlieParker A bit late, but just python3 setup.py develop should work? – Manoj Mar 12 '17 at 19:57
  • 3
    It works with python3, but don't forget to remove any current pip installation you may have, as they will clash together (it happened to me at the moment). – Léo Germond Apr 07 '17 at 12:38
  • How to find the location of the link file that installs this? It is not in the usual place and I can not uninstall a package. – mathtick Mar 03 '19 at 20:12
  • 1
    So when should someone use `pip install -e` and when `python setup.py develop`? It seems like the former is always prefered? – yifanwu Jan 14 '21 at 07:50
  • 1
    @yifanwu I guess when you are sure that `python setup.py develop` works reliably, and you want to avoid installing pip, like for example when quickly debugging a package on a remote machine – Erik Kaplun Jan 21 '21 at 10:09
  • 1
    Hi, since "python -m build" is now recommanded over "setup.py install", should we still use the "develop" command or should we use other alternatives? – Eric Burel Sep 02 '22 at 19:45
  • @EricBurel see https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#working-in-development-mode – Erik Kaplun Sep 04 '22 at 17:57
156

From the documentation. The develop will not install the package but it will create a .egg-link in the deployment directory back to the project source code directory.

So it's like installing but instead of copying to the site-packages it adds a symbolic link (the .egg-link acts as a multiplatform symbolic link).

That way you can edit the source code and see the changes directly without having to reinstall every time that you make a little change. This is useful when you are the developer of that project hence the name develop. If you are just installing someone else's package you should use install

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
RubenLaguna
  • 21,435
  • 13
  • 113
  • 151
32

Another thing that people may find useful when using the develop method is the --user option to install without sudo. Ex:

python setup.py develop --user

instead of

sudo python setup.py develop
while
  • 3,602
  • 4
  • 33
  • 42
K.S.
  • 2,846
  • 4
  • 24
  • 32
  • 18
    IIUC you should never `setup.py develop` in your system, this only makes sense in a virtualenv. – dividebyzero Dec 16 '16 at 14:11
  • 3
    @dividebyzero Do you mean one should always use `python setup.py develop --user`, if I understand correctly? Besides, could you please tell me where the package is installed by using `python setup.py develop --user`? Thanks! – ROBOT AI Dec 16 '16 at 18:58
  • 3
    I think the `--user` will install in a directory in your home account, and will not affect other users in your system. The `develop` will make links to your project source directory instead of actually copying everything. `develop --user` should be OK, and `develop` in a virtualenv too. Only `develop` to the actual system is weird, because you may have other users using something that points to the project in your personal copy of the project source code. – dividebyzero Dec 19 '16 at 12:39
  • 6
    Many (most?) people aren't running on multi-user systems though – patstew Jan 12 '17 at 15:55
  • I'd say most devs are running on multi-user systems. Mac and Linux desktops are probably the majority of developers out there these days. – boatcoder Oct 18 '17 at 18:16
  • Where can I find a list of setup.py switches? I feel like there should be a --no-deps somewhere... – Lucas Soares Nov 18 '17 at 18:15
  • 3
    I don't see how this answers the question as asked. – Baum mit Augen Nov 12 '18 at 21:17
  • 2
    @boatcoder, Mac and Linux (and Windows) might be multi-user _capable_ systems, but most likely the developer is the only (real) user account of his desktop, and I believe that's what pastew meant. – MestreLion Nov 05 '19 at 11:38