0

I understand that it is possible to install packages from git and pip using the command below.

pip install git+git://github.com/author/package.git@master

So basically what this new command should do is that,

It should install all the packages necessary in my local just by using names or more precisely without me uploading the full package to git, only their names.

So Basically, I am trying to replicate this command with git.

pip install -r requirements.txt

Is this even possible? Has anyone done it?

Examples: Requirements.txt contain :

pandas==1.0.4 
matplotlib==3.2.1 
numpy=1.18.5

So something in the git with setup.py along the lines of it to install that package, if possible.

import pip 

    with open('requirements.txt','r') as fh:   
      for line in fh.readlines():
        pip install line
High-Octane
  • 1,104
  • 5
  • 19

1 Answers1

1

Still not sure I fully understand, what is the goal here...

Maybe you want to somehow have the requirements.txt file in a git repository and have it installed with pip. The goal being to have the requirements version controlled.

I believe you could achieve something to that effect with some kind of fake Python package that has no code, only dependencies.

Place the following 2 files in a MyDependencies git repository:

setup.py

#!/usr/bin/env python3

import pathlib

import pkg_resources
import setuptools

with pathlib.Path('requirements.txt').open() as requirements_txt:
    install_requires = [
        str(requirement)
        for requirement
        in pkg_resources.parse_requirements(requirements_txt)
    ]

setuptools.setup(
    name='MyDependencies',
    version='0.0.0',
    install_requires=install_requires,
)

requirements.txt

pandas==1.0.4 
matplotlib==3.2.1 
numpy=1.18.5

Then the dependencies can be installed like so:

path/to/pythonX.Y -m pip install --upgrade git+git://github.com/username/MyDependencies.git@master

If I am not mistaken, this should do the trick.

References:

sinoroc
  • 18,409
  • 2
  • 39
  • 70