0

My Code : https://www.paste.org/103827 I have written a small piece of code which works scraps HTML table containing COVID19 data and transforms it into pandas dataframe.

Then it saves that dataframe as csv.

I want to make single executable file such that anyone can download that file and if they run it COVID19 data will be saved as csv on that location.They should not need to install any of the dependencies(not even Python).

Just wanted to ask if this is possible, if yes then please tell me how. I am a complete beginner. Using Linux(Manjaro KDE)

EDIT

I tried pyinstaller and was able create a single executable file of size 362 MB but this error occurred

Traceback (most recent call last): File 
"PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 13, in <module> 
File "/home/sharma/.local/lib/python3.7/site- 
packages/PyInstaller/loader/pyimod03_importers.py", line 623, in 
exec_module exec(bytecode, module.__dict__) File "site- 
packages/pkg_resources/__init__.py", line 86, in <module> 
ModuleNotFoundError: No module named 'pkg_resources.py2_warn' [74226] 
Failed to execute script pyi_rth_pkgres 

I am getting this error when I run this 362 MB file.

Polar
  • 63
  • 9
  • 1
    Does [this answer](https://stackoverflow.com/q/15399532/1435475) help you? – guidot Mar 25 '20 at 13:21
  • 1
    Have you done any research? There is already plenty of information available on the subject. – AMC Mar 25 '20 at 16:50
  • 3
    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) – AMC Mar 25 '20 at 16:51
  • @guidot py2exe is for Windows only I guess? I don't know much. I tried pyinstaller and was able to get 362 MB executable file which is still showing error. – Polar Mar 25 '20 at 17:01

1 Answers1

2

You can try PyInstaller. It is easy to use for a simple case.

pip install pyinstaller

then for a single-file executable

pyinstaller covid_19.py --onefile

will generate the executable in the \dist directory.

PyInstaller is not cross platform, so on Windows, for example, it will create a .exe file. If you wanted an executable to work on, say, MacOS, you would need to compile on that system.

wstk
  • 1,040
  • 8
  • 14
  • Sorry I forgot to mention that I have already tried pyinstaller(on Manjaro KDE) . It gave me recursion depth error, so I read somewhere on stackoverlow that changing recursion limit in **.spec** file may help. I tried that, it worked when I ran command pyinstaller --onefile covid_19.py but there was a single folder in `\dist` and in that folder there were too many files and folders with all the module names like pandas,numpy,matplotlib etcetra. I have installed anaconda on my system. _Very sorry that I did not mention it before_ – Polar Mar 25 '20 at 15:44
  • 1
    Running with the `--onefile` flag should generate a single `.exe` file in the `\dist` directory. It sounds like you ran it without that flag. In this case it would generate a folder inside `\dist` with the same name as the script, and in *that* folder you would find the `.exe` as well as lots of other stuff. Are you sure you ran with the `--onefile` flag (with TWO dashes?). You can also use `pyinstaller covid_19.py -F` [I guess I should say that this is for Windows. For your Linux setup I can't say for 100% this would be the case] – wstk Mar 25 '20 at 16:21
  • @Thank you for helping, I tried again and yes finally I got one single file ins `\dist` folder but file size is 362 MB. Is it expected(please see my code), isn't it too large? – Polar Mar 25 '20 at 17:04
  • `Traceback (most recent call last): File "PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 13, in File "/home/sharma/.local/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module exec(bytecode, module.__dict__) File "site-packages/pkg_resources/__init__.py", line 86, in ModuleNotFoundError: No module named 'pkg_resources.py2_warn' [74226] Failed to execute script pyi_rth_pkgres ` I am getting this error when I run this 362 MB file. Please help. – Polar Mar 25 '20 at 17:10
  • 1
    362 MB seems very large. On Windows when I take your code and compile it, it's about 30 MB, which seems more normal. What version of Python and PyInstaller are you using? – wstk Mar 25 '20 at 19:08
  • Thank you for still replying, I am using Python 3.7 which was installed with anaconda. And installed pyinstaller 3.6 with pip – Polar Mar 26 '20 at 20:07