1

I have a python project which takes in a bunch of pdf files from a directory, scrapes data from them, and then does some matching of that scraped data with some data in a CSV file.

The whole work has 2-3 python scripts, used as modules, and also uses dependencies of pdftotext, pandas, NumPy, etc.

Now I can pip freeze my Conda env and it can give me a requirements.txt file with all packages to install.

However, I want this main python script (which calls other modules and runs the whole project) to be run by a less technical person who doesn't work on pandas and other such python stuff.

So is there a way I can make this whole project as an executable file that encapsulates all dependencies, packages, scripts, and just running that executable in the terminal should run the whole project without having the other person install all dependencies themselves using requirements.txt file.

I can't use docker unfortunately as that is not permitted right now for my work.

I was thinking buck build if that works?

https://buck.build/

or if there is an easy way?

Thanks!

Baktaawar
  • 7,086
  • 24
  • 81
  • 149
  • Which OS would you want to execute the program on? – Manumerous Jun 03 '20 at 20:37
  • 2
    Does this answer your question? [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) – Debdut Goswami Jun 03 '20 at 20:38
  • What operating system are you using? Is the target operating system the same? Have you looked at the various tools to make executables, such as PyInstaller? – MisterMiyagi Jun 03 '20 at 20:38
  • Have a look at PyInstaller or Nuitka. – Tiger-222 Jun 03 '20 at 20:38
  • macos or if run on server, then linux. But is it possible to run it on any os? Target OS would either be macos (if run on laptop). or Linux if run on server. Same as me. – Baktaawar Jun 03 '20 at 21:10
  • What do u think of Buck? https://buck.build/ – Baktaawar Jun 03 '20 at 21:19

2 Answers2

1

One approach is to package the Python application directory as a .zip file and execute that. Zip files that have a __main__.py entry point can be run this way.

This can be done easily in version 2.6 and up. Additional “zipapp” support was added in 3.6.

The main challenge has to do with compatibility for non-pure-Python libraries. What you zip up needs to be compatible with the machine where it will be run.

Chris Johnson
  • 20,650
  • 6
  • 81
  • 80
  • could u help broaden the above ans? What do u mean zip it using zipapp support? Is that a package which helps me zip the whole python project? The difference is the direcotry of pdf files are not going to be fixed. SO end user passes a directory path to the pdf files via cli and python script takes that via argparser and then does os.walk to scrape data etc. – Baktaawar Jun 03 '20 at 21:13
  • Many good articles on this, e.g. https://gist.github.com/asimjalis/4237534. Try it and see how it works. This is 100% about the Python app, 0% about your input files — the app can process any input you want, just like in a non-zipped app. – Chris Johnson Jun 04 '20 at 13:46
0
pip install cx_freeze

cxfreeze main.py --target-name your_exe_name

Replace your_exe_name. It will generate a build folder with your .exe in it.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Drew
  • 1