J Doe
J Doe

Reputation: 53

How do I package a single python script which takes command line arguments and also has dependencies?

I have a single Python file which is supposed to take in a bunch of inputs during the command.

For eg: python script.py "string_1" "string_2"

I also have a bunch of dependencies including pandas, datetime and even Python3.

I want to package all this code in a manner that anyone can install the package along with the dependencies as well (in a directory or so) and then just call the script/module : in the above manner. Without having to actually go into a Python interpreter.

I tried using the python-packaging resource, but with that I would need to go into the interpreter, right ?

Upvotes: 4

Views: 1668

Answers (3)

user368604
user368604

Reputation: 166

If you can rely on a base install of python being present already.

Then it's worth looking at Python's zipapp module introduced in Python3.5 https://docs.python.org/3/library/zipapp.html#creating-standalone-applications-with-zipapp For background info PEP441 https://www.python.org/dev/peps/pep-0441/

Also there is a project called Shiv which adds some extra abilities to the zipapp module bundled in python3.5

https://shiv.readthedocs.io/en/latest/

Upvotes: 1

dwagon
dwagon

Reputation: 511

Have a look at pex (https://pex.readthedocs.io/en/stable/). It wraps up your python scripts, files, dependencies, etc into a single executable. You still need the python interpreter installed, but it includes everything else.

Upvotes: 0

pittix
pittix

Reputation: 171

I found a good article today that explains quite well the procedure: https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263

pyinstaller --onefile <script.py> is the tl;dr on linux. On windows you need also py32exe

Upvotes: 1

Related Questions