How do you Install a Python Package from a GitHub Repository?
To install a Python package from GitHub, you first need to install the Python form and then install pip. If pip is not installed in your system, then install the pip. After installing, you have to install git bash in Windows.
Now, after installing Python, pip and git bash for installing the package, you need to clone the repository and fetch and check out the comment that is desired. Then, the pip will build a package into a wheel and then install that wheel, and if there is any dependency, then it will install all the dependencies.
Syntax:
$ pip install "Package" @ git+"URL of the repository."
To install the pip package, run the command given below:
Command:
$ pip install pip@git+https://github.com/pypa/pip
As the Python PIP package comes in Python by default, when you run the above command in the command prompt, you will see the output as:
Output:
Requirement already satisfied: pip@ git+https://github.com/pypa/pip from git+https://github.com/pypa/pip in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (20.2.3)
If you want to see the pip version you have in your Python, then type the following command in the command prompt:
Command:
$ pip --version
After running the above command, you will see the pip version you have in your Python.
Output:
pip 20.2.3 from c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)
If you want to install any package type, use the command given below in the command prompt and replace the packageName with the package you want to install.
Command:
$ pip install -e git+github-url-of-the-package#egg=packageName
Suppose you want to install the flask package type,e the command given below:
Command:
$ pip install -e git+github-url-of-the-package#egg=flask
Output:
Obtaining flask from git+https://github.com/pallets/flask#egg=flask
Cloning https://github.com/pallets/flask to c:\users\aditya shakya\src\flask
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: flask in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (3.0.0)
Requirement already satisfied: importlib-metadata>=3.6.0; python_version < "3.10" in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from flask) (6.8.0)
Requirement already satisfied: Jinja2>=3.1.2 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from flask) (3.1.2)
Requirement already satisfied: click>=8.1.3 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from flask) (8.1.7)
Requirement already satisfied: Werkzeug>=3.0.0 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from flask) (3.0.0)
Requirement already satisfied: itsdangerous>=2.1.2 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from flask) (2.1.2)
Requirement already satisfied: blinker>=1.6.2 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from flask) (1.6.3)
Requirement already satisfied: zipp>=0.5 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from importlib-metadata>=3.6.0; python_version < "3.10"->flask) (3.17.0)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from Jinja2>=3.1.2->flask) (2.1.3)
Requirement already satisfied: colorama; platform_system == "Windows" in c:\users\aditya shakya\appdata\local\programs\python\python39\lib\site-packages (from click>=8.1.3->flask) (0.4.6)
WARNING: You are using pip version 20.2.3; however, version 23.3.1 is available.
You should consider upgrading via the 'c:\users\aditya shakya\appdata\local\programs\python\python39\python.exe -m pip install --upgrade pip' command.
Since Flask is already installed in my system, it shows requirement is already satisfied. So, if you want to install any package, you can run the following command.