Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spestana/dd7bf085ac3ba34968d7f98fdd8a0dfa to your computer and use it in GitHub Desktop.
Save spestana/dd7bf085ac3ba34968d7f98fdd8a0dfa to your computer and use it in GitHub Desktop.

Pip is a package manager of python. You can download Python libraries from some Python repositories like PyPI. You can also download libraries from a git repository. This is gonna be the issue to be explained in this article.

I don't like to memorize things all the time. So, I guess, I couldn't be working without internet :). Whenever I need to install some python libraries from a git repositories, I see a lot of way to do it. It is really confusing. This should be the reason why I can't memorize it. I can see how a very simple requirement is handled with to many confusing way. There shouldn't be to many way. Some of them is not working neither. At last, I decided to blog it.

As you may know, you can use two protocols which are http and ssh to do something on git repositories. Using protocol ssh instead of http may provide some ease of use. Because of nature of ssh, you can do something with your primary/public keys. So, you don't have to input your credentials all the time. But I'll be giving a way for both;

Here are the example with bitbucket git repositories;

#For HTTP

pip install git+https://bitbucket.org/<project_owner>/<project_name>
#Example: pip install git+https://bitbucket.org/egemsoft/esefpy-web
#For SSH

pip install git+ssh://git@bitbucket.org/<project_owner>/<project_name>.git/
#Example: pip install git+ssh://git@bitbucket.org/egemsoft/esefpy-web.git
#For Local Git Repository

pip install git+file///path/to/your/git/project/
#Example: pip install git+file:///Users/ahmetdal/workspace/celery/

To install from a github repository, and to install dependencies as specified by a requirements.txt file in that repository, we can do the following (note the -r flag when we install from the requirements.txt file):

# For HTTP

pip install git+https://github.com/<project_owner>/<project_name>.git@<branch_name>
#Example: pip install git+https://github.com/spestana/gtsa@main

pip install -r https://raw.githubusercontent.com/<project_owner>/<project_name>/<branch_name>/requirements.txt
#Example: pip install -r https://raw.githubusercontent.com/spestana/gtsa/main/requirements.txt

You may also need to use the --force-reinstall flag:

pip install --force-reinstall -r https://raw.githubusercontent.com/<project_owner>/<project_name>/<branch_name>/requirements.txt
#Example: pip install --force-reinstall -r https://raw.githubusercontent.com/spestana/gtsa/main/requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment