0

I'm working on a simple script for a friend who isn't knowledgeable about programming at all. My script uses several libraries installed from external sources via pip (requests, BeautifulSoup, etc.). I would like to send my script to my friend with as little set-up on his end as possible, but can't figure out how to include those external libraries in the repository. Is there a 'proper' or best way to package those libraries so that the user of the script doesn't have to install them manually?

I've looked into using venv or a setup.py file, but I'm not sure if either of those is an appropriate approach or how to implement those solutions.

awu
  • 5
  • 3
  • It’s pretty common to include a `requirements.txt` file in the repo that lists all the dependencies. These can the be easily installed with `pip install -r /path/to/requirements.txt` preferably in a virtual env. – Mark Aug 16 '21 at 02:29
  • https://stackoverflow.com/search?q=%5Bpython%5D+standalone+script – phd Aug 16 '21 at 10:17

2 Answers2

1

I'd say that the user installing the packages/modules manually is common practice when exploring a distributed project.

However, perhaps the concept of a requirements file may be pertinent here.

Before pushing your project to your repo (or even after is fine), in your local project directory run a pip freeze command like:

pip freeze > requirements.txt

(or some variation of that, Google it if that doesn't work)

which will freeze the names of your installed modules into a file called requirements.txt.

When someone wants to run any code from your project when they download the repo, they can quickly install all necessary packages with

pip install -r requirements.txt

Read Pip Documentation Here

0

I'm not aware of a way to package the dependencies with your script.

However, a simple way to make sure your friend has all the dependencies is to create a requirements.txt, in which you list all the requirements (one per line, with version number if you need)

eg, the requirements.txt could look like this:

requests
BeautifulSoup
numpy
matplotlib

And then run:

pip install -r requirements.txt
Owen
  • 56
  • 1
  • 8