pythonpippython-module

How to prevent `pip install` resulting in duplicate code?


I am working on a library with some others. Our git repo (called modulename) looks like this

modulename/
  src_file_1.py
  src_file_2.py
tests/
  ...
.../

The instructions are to clone this somewhere in home, so I now have

~/
  modulename/
    modulename/
      src_file_1.py
      src_file_2.py
    tests/
      ...
    .../

and then run pip install . from inside the first modulename. After that, when I look in site-packages, I have

site-packages/
  modulename/
    src_file_1.py
    src_file_2.py

so pip has copied the source into site-packages

The problem I how have, is that when I make changes to the cloned repository, those changes are not copied into site-packages, so when I use the module in some other code, I only see the version copied when I did pip install .. I'm in a bit of a mess here. What is the proper way to work on this library so I can commit my changes back to git and also import the module from other places on my machine?


Solution

  • When using pip install for development, you are supposed to use a flag --editable.

    pip install -e .
    

    That way, no copy of implementation is done and your edits to original files affect all programs executed in that Python environment.