Python: how to edit an installed package?

PythonPip

Python Problem Overview


I installed some package via pip install something. I want to edit the source code for the package something. Where is it (on ubuntu 12.04) and how do I make it reload each time I edit the source code and run it?

Currently I am editing the source code, and then running python setup.py again and again, which turns out to be quite a hassle.

Python Solutions


Solution 1 - Python

You should never edit an installed package. Instead, install a forked version of package.

If you need to edit the code frequently, DO NOT install the package via pip install something and edit the code in '.../site_packages/...'

Instead, put the source code under a development directory, and install it with

$ python setup.py develop

or

$ pip install -e path/to/SomePackage

Or use a vcs at the first place

$ pip install -e git+https://github.com/lakshmivyas/hyde.git#egg=hyde

Put your changes in a version control system, and tell pip to install it explicitly.

Reference: Edit mode

Solution 2 - Python

You can edit the files installed in /usr/local/lib/python2.7/dist-packages/. Do note that you will have to use sudo or become root. The better option would be to use virtual environment for your development. Then you can edit the files installed with your permissions inside your virtual environment.

Solution 3 - Python

I too needed to change some things inside a package. Taking inspiration from the previous answers, You can do the following.

  1. Fork the package/repo to your GitHub
  2. clone your forked version and create a new branch of your choice
  3. make changes and push code to the new branch on your repository
  4. you can easily use pip install -e git+repositoryurl@branchname
  5. There are certain things to consider if its a private repository

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKJWView Question on Stackoverflow
Solution 1 - PythonLeonardo.ZView Answer on Stackoverflow
Solution 2 - Pythonoz123View Answer on Stackoverflow
Solution 3 - PythonKaran MittalView Answer on Stackoverflow