Last Updated: September 21, 2021

PIP Install Git – A quick read

pip install git quick read

Try a faster and easier way to work with Python packages like Exchangelib. Use Python 3.9 by ActiveState and build your own runtime with the packages and dependencies you need. Get started for free by creating an account on the ActiveState Platform or logging in with your GitHub account.

Pip/pip3 is the official package manager for Python, and is the tool recommended by the Python Packing Authority (PyPA) for installing Python packages. The term ‘pip’ is used interchangeably with ‘pip3’ in this Quick Guide.

By default, pip installs packages and all their required dependencies from the Python Package Index (PyPI), using the command:

pip install <package_name>.

However, pip doesn’t currently support dependency resolution, which can lead to corrupted environments. To avoid this, you may want to try the ActiveState Platform, which is the only Python package management solution that automatically resolves dependencies, flags conflicts, and will even suggest a manual workaround to resolve the conflict. Get started with the ActiveState Platform by signing up for a free account.

Git Version Control

Git is a Version Control System (VCS) for managing changes in source code, as well as other types of files (eg. html) and file structures in Git repositories. It allows developers to collaborate on projects without conflict.

PIP Install Git logo

A Git repository is a .git/ folder inside a software development project. You can deploy Git locally, or use it via a hosted service, such as Github, Gitlab or Bitbucket.

One of the advantages of using pip together with Git is to install the latest commits of unreleased Python packages as branches from Github. Some examples of this are provided below.

Git Installation Prerequisites

First determine whether you have up-to-date versions of Python, pip, and Git. You can check which version of Python (if any) is installed, by entering the following command in a terminal or command window:

python --version

Output should be similar to:

Python 3.8.2

You can check if pip is already installed and up-to-date by entering the following command:

pip --version 

Output should be similar to:

pip 20.0.2 from C:\Python38\lib\site-packages\pip (python 3.8)

If either Python or pip is not installed or up-to-date, the simplest way to get an up-to-date Python version with pip for either Linux, MacOS or Windows, is to install Python 3.9 from ActiveState

Git Installation

Before installing Git, you should first determine whether you have it installed by running the following git command:

git --version

Output should be similar to:

git version 2.32.0.windows.2

For Linux

Most Linux platforms already have a basic Git installation by default, but they are generally not up-to-date. Git installation commands for various Linux platforms are listed here:

  • Debian-based installation, such as Ubuntu:
sudo apt install git-all

or 

apt-get install git
  • RHEL and CentOS:
sudo dnf install git-all
  • Fedora:

# Up to Fedora 21:

yum install git

# Fedora 22 and later:

dnf install git 
  • openSUSE:
zypper install git

For macOS:

Although MacOS comes with a command line tools installer that includes Git, Homebrew is the recommended option for macOS Git installation. 

To install Homebrew, run the following script in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed, you can install Git with the following command:

brew install git

For Windows:

To install Git for Windows, point your browser at https://git-scm.com/download/win. A download of the Windows Git installer will begin automatically. Once complete, you can double-click the installer and follow the steps. 

First-Time Git Setup 

Once Git is installed, your Git environment and configuration variables need to be customized with git config

You can view your default Git configuration options with the following command:

git config -h

Output should be similar to:

usage: git config [<options>] 

...   

Set Your Git Identity

Set your user name and email address. This is important because every Git commit uses this information:

git config --global user.name "John Doe"

git config --global user.email johndoe@example.com

This only needs to be done once on each computer, if you include the –global option.

After you have set your user name and email address, you can check your settings with the following command:

git config --list

Git Usage

Once your Git identity has been configured, you can begin using Git to install Github branches. 

Pip Install Git Syntax

The following command syntax can be used to install the default branch of a github project: 

pip install git+https://github.com/<owner_name>/<repo_name>.git

Pip Install Git Branch – Example

To install the latest commit of the Exchangelib package, run:

pip install git+https://github.com/ecederstrand/exchangelib

Pip Install Git Subdirectory

This feature is not yet available.

Pip Install Git Version

To pip install a specific version of a repository branch, enter:

pip install https://git+github.com/<owner_name>/<repo_name>.git.@<version#> 

Pip Install Git Requirements.txt 

 To include Git dependencies and submodules dependencies, located at:

https://github.com/<owner_name>/<repos_name>.git@<version#>  

in a requirements.txt file:

# requirements.txt should include:

packageA==<version#>

-e https://github.com/<owner_name>/<repo_name>.git@<version#>#egg=<repo_name>

# Install requirements.txt file with -r flag:

pip install -r requirements.txt

Git Clone – Syntax

The Git clone command is used in cloning or downloading a Git project without installing it. 

First navigate to the directory where you to locate the cloned repository, then enter: 

 git clone https://github.com/<owner_name>/<repo_name>

Github Desktop – Clone with SSH Option

Github Desktop is a Windows Github Git client for cloning. It has an SSH authentication option that requires a public SSH key. A link with directions is included.

SSH Pip install git

Figure 1. Github Desktop > Clone > SSH Option:

Pip Install Git With SSH

The following syntax will use SSH to install a Git repository that is not password protected:

pip install git+ssh://github.com/<owner_name>/<repo_name>.git@<version#>#egg=<repo_name>

A modern solution to Python package management – Try ActiveState’s Platform

Dependency resolution is at the core of the ActiveState Platform. When you create a project and start adding requirements, the Platforms tell you what dependencies those requirements have.

The ActiveState Platform is a cloud-based build tool for Python. It provides build automation and vulnerability remediation for:

  • Python language cores, including Python 2.7 and Python 3.5+
  • Python packages and their dependencies, including:
  • Transitive dependencies (ie., dependencies of dependencies)
  • Linked C and Fortran libraries, so you can build data science packages
  • Operating system-level dependencies for Windows, Linux, and macOS
  • Shared dependencies (ie., OpenSSL)
  • Find, fix and automatically rebuild a secure version of Python packages like Django and environments in minutes

Python 3.9 Web GUI ScreenshotThe ActiveState Platform aims to handle every dependency for every language. That means handling libraries down to the C/C++ level, external tools, and all the conditional dependencies that exist. To take things even further, our ultimate goal is to support multi-language projects. That means that you can create a project using both Python and Perl packages, and we’ll make sure that both languages are using the same (up to date) OpenSSL version.

Python Package Management In Action

Get a hands-on appreciation for how the ActiveState Platform can help you manage your dependencies for Python environments. Just run the following command to install Python 3.9 and our package manager, the State Tool:

Windows

powershell -Command "& $([scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://platform.activestate.com/dl/cli/install.ps1'))) -activate-default ActiveState-Labs/Python-3.9Beta"

Linux

sh <(curl -q https://platform.activestate.com/dl/cli/install.sh) --activate-default ActiveState-Labs/Python-3.9Beta

Now you can run state install <packagename>. Learn more about how to use the State Tool to manage your Python environment.

Let us know your experience in the ActiveState Community forum.

Watch this video to learn how to use the ActiveState Platform to create a Python 3.9 environment, and then use the Platform’s CLI (State Tool) to install and manage it.

Suhani S