The problem:

  • I don’t understand the difference between develop and install
  • I don’t understand the difference between develop and pip install -e [dir]
  • I don’t see the changes to my code when I import my code

The difference between develop and install

In short, you want to run develop when you are editing code because when you run install, it will copy your code into site-packages thus if you want to test your latest code you will need to install (copy) again. On the other hand, with develop, it creates a link to your source code so that when you import your code, it is your latest code.

Let’s take a look.

note: to keep it simple, I’m going to assume that you have created virtual environment and using python3.

cd ${project-dir}
python3 -m venv env
source env/bin/activate
pip install -U setuptools
easy_install --version
setuptools 38.5.1 from ${project-dir}/env/lib/python3.6/site-packages (Python 3.6) develop simply creates a special .egg-link file in site-packages directory which links to your project’s source code.

$ cd ${project-dir}
$ python develop
$ ls -l env/lib/python3.6/site-packages | grep myproject
-rw-r--r--    1 nreeves  staff      44 Mar  5 14:11 myproject.egg-link
$ cat env/lib/python3.6/site-packages/myproject.egg-link

When you list package, you can see it shows source directory instead of package name

$ pip list --format=columns | grep myproject
myproject                                0.1    ${project-dir}/src

and when you see path to source code, it is the file under my project folder and not inside site-package

>>> import myproject
>>> myproject.__file__

Let’s uninstall that for now so that we can see what install will do. You can see it is simply removing .egg-link file

$ python develop --uninstall
running develop
Removing ${project-dir}/env/lib/python3.6/site-packages/myproject.egg-link (link to src)

Spoiler alert! if you run find . -name 'myproject.*', you will see residual but this is good enough for now.

Now to install with install. You will see build process then copying bunch of files to site-packages

$ python install
running install
running build
running build_py
copying build... -> ${project-dir}/env/lib/python3.6/site-packages/myproject/...

When you list package, you only see package name unlike the one with develop

pip list --format=columns | grep myproject
myproject                               0.1

and when you see path to source code, the path to the file is inside of site-packages

>>> import myproject
>>> myproject.__file__

So the reason you might not see your new code could be:

  • At one point you ran python install so make sure to remove them.
  • You made changes and forgot to restart the program. Python will load files when program started, compile it to bytecode and keep it internally.

But wait… instead of, use pip

It is highly recommended to use pip instead of pip install . instead of install and pip install -e . instead of develop.

Because will do the wrong things for dependencies such as:



Great tools to decided refnanice Continue reading

Smile every time you sudo

Published on February 18, 2021

Don't let your money sleep

Published on December 20, 2020