Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 359
J Doe Avatar asked Oct 21 '25 11:10

J Doe


2 Answers

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

like image 174
pittix Avatar answered Oct 24 '25 00:10

pittix


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/

like image 35
user368604 Avatar answered Oct 24 '25 01:10

user368604



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!