Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What if the end-user didn't have the required library?

My Python project uses various kind of libraries. What is the protocol if the end-user didn't have one or any of them?

Should a window pop up and notify him/her which package and version to download in his/her environment? Or I should include the libraries within my project?

What's the proper action?

like image 741
Kepler 186 Avatar asked May 02 '19 13:05

Kepler 186


4 Answers

Whatever your project is, you could try making it into a python package that the end-user would install. The way this works is

In the root directory of your package you would include a setup.py. You could include in this file a list of requirements/dependencies (the install_requires key) that would be installed along with your package when the end-user installs it.

The end user could then use pip to install your package eg

pip install YourPackage

and all dependencies listed in setup.py would be installed first.

Additionally, as @Devesh Kumar Singh pointed out in his comment, you could also include a requirements.txt file. The user could then install using this file with

pip install -r requirements.txt YourPackage

See this guide for building a python package, setuptools documentation

like image 176
RSHAP Avatar answered Oct 19 '22 21:10

RSHAP


To show other users, what libraries are needed for your project, you have multiple options. All options are some kind of files, that say which libraries are needed for this project.

Files that I am aware of

  • requirements.txt: very simple
  • setup.py: Used when you publish your project on sides like pypi https://stackoverflow.com/a/1472014/8411228
  • Pipfile: The way to go when you work in an virtualenv https://pipenv.kennethreitz.org/en/latest/
  • environment.yml: Used for Conda environments https://tdhopper.com/blog/my-python-environment-workflow-with-conda/#fn:requirements-conda
like image 20
Uli Sotschok Avatar answered Oct 19 '22 20:10

Uli Sotschok


Another option: You can use PyInstaller to freeze (packages) Python applications into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX.

PyInstaller Quickstart

This has worked very well for me. Indeed, you do not have to worry about whether the final user has Python installed.

like image 4
user11293039 Avatar answered Oct 19 '22 20:10

user11293039


Here is where packaging a python project into a module comes handy modules We include a requirements.txt file which contains all python module requirements needed for that python library, and installs them automatically when the module is setup.

A good primer on how to setup your module to be distributable is Structuring your project

like image 1
Devesh Kumar Singh Avatar answered Oct 19 '22 21:10

Devesh Kumar Singh