4

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?

0

2 Answers 2

1

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']
)



Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Thanks for the help, I'll try this out. Quick question then, what should go in a dependencies folder if not the packages I need?
I have no idea, I've never used it. If you use a venv then all dependencies are installed on the same place, available for any project that uses the same venv. Which is pretty nice since you only need to install each package once! In pycharm you can see all installed packages at File -> Settings -> Project: * -> Project Interpreter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.