4

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 ?

RMPR
  • 3,368
  • 4
  • 19
  • 31
J Doe
  • 53
  • 6
  • Consider using a tool like py2exe (for Windows deployments). Auto installing Python packages is not a trivial problem. – Nidal Mar 20 '19 at 22:34
  • Possible duplicate of [How to make a Python script standalone executable to run without ANY dependency?](https://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency) – phd Mar 21 '19 at 00:28

3 Answers3

1

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

pittix
  • 161
  • 12
1

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/

user368604
  • 166
  • 3
0

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.

dwagon
  • 501
  • 3
  • 9