Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add/install python libraries to my github project?

I'm building my first project on GitHub and my python src code uses an open-source, 3rd-party library that I have installed on my computer. However, I heard it is best practice to create a dep (dependencies) folder to store any additional libraries I would need. How do I actually install the libraries in the dep folder and use them from there instead of my main computer?

like image 913
AnonUser456 Avatar asked Nov 03 '25 12:11

AnonUser456


2 Answers

You have to create a requirements.txt file with each package on a separate line. e.g.

pandas==0.24.2

You also might want to add a setup.py to your python package. In the setup you have to use "install_requires" argument. Although install_requires will not install packages when installing your package but will let the user know which packages are needed. The user can refer to the requirements.txt to see the requirements. You can check it here: https://packaging.python.org/discussions/install-requires-vs-requirements/

The following is an example of setup.py file:

from distutils.core import setup
from setuptools import find_packages

setup(
    name='foobar',
    version='0.0',
    packages=find_packages(),
    url='',
    license='',
    author='foo bar',
    author_email='[email protected]',
    description='A package for ...'
    install_requires=['A','B']
)



like image 134
maede rayati Avatar answered Nov 06 '25 03:11

maede rayati


Never heard about installing additional libraries in a dependencies folder.

Create a setup python file in your root folder if you don't already have it, in there you can define what packages (libraries as you call them) your project needs. This is a simple setup file for example:

from setuptools import setup, find_packages

setup(
    name = "yourpackage",
    version = "1.2.0",
    description = "Simple description",
    packages = find_packages(),
    install_requires = ['matplotlib']  # Example of external package
)

When installing a package that has this setup file it automatically also install every requirement in your VENV. And if you're using pycharm then it also warns you if there's a requirement that's not installed.

like image 37
Mandera Avatar answered Nov 06 '25 03:11

Mandera