Search code examples
python-3.xopen-sourcepython-import

Correctly patching Python open source package without package clashing


I debated which Stackoverflow site this best fit but couldn't decide.

I'd like to contribute to an open-source project on Github, but I can't figure out how to prevent the stable version already installed on my machine and the development version I'd like to make a patch for from clashing on import.

The repository only suggests pip installing with the editable.

What I've done so far is: clone the repository locally, and then trying to import it in a Jupyter Notebook from the directory above. However, the Jupyter Notebook is referencing the stable version installed earlier with pip. I tried to append to sys.path the child directory holding the package but still the same issue. I can't seem to get relative imports working either. Do I need to uninstall the stable version?

Any tips are appreciated!


Solution

  • You'd use virtualenv for this. It will allow you to create an environment that is isolated from your system python and you can install the dev version of the library on it.

    Basic usage (for Unix-like systems) is:

    $ pip install virtualenv
    $ virtualenv MY_ENV
    $ cd MY_ENV
    $ source bin/activate # activates the local python for this shell only
    (MY_ENV)$ pip install <some-module> # installs to a local and isolated python
    (MY_ENV)$ python ... # runs python in the local environment
    (MY_ENV)$ deactivate  # disable the isolated python
    $