8
I’m doing a service where I have to do a program that reads and creates files with numerical data. The problem I have is that the computers on which the program will be used are not accessible to me.
Because of this, I needed to convert my file .py
for .exe
The program is ready in Python 3.5
and it seems that the only program that can help make the conversion is the CX_FREEZE
. I used it and formed a file...
I have 2 problems:
The file does not work on computers that are windows 7 (depending on the version) and that do not have some dlls (they are not always the same)
The Executable is coming accompanied by SEVERAL folders with MANY files. This doesn’t seem feasible, wanted some way to "package" the files inside my executable.
The program is not so big, and does not use so many libraries, only OS and DATETIME.
I have tried using Pyinstaller and INNO setup, but none gives me any light.
I wonder if anyone has any alternatives or tips that I can use.
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os", "datetime"], "excludes": []}
base = None
if sys.platform == "win32":
base = "Console" # para execuções em terminal
setup(name="GetSpecJoin",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("240117.py", base=base)])
The additional files are the dependencies (Python and libraries used, including perhaps cx_freeze itself). Sending multiple files should not be an impediment for you. Is there that question on Soen with answers that may be useful to you. But I didn’t test, I don’t know if it works what they say there. Anyway, if you really want to have one file and do not want to request the installation of Python in the client, maybe it is better to simply use another language (C, for example).
– Luiz Vieira
I understand that this would be the most guaranteed alternative. If I don’t get an answer in a few days I will have to do this. The fact is that the client does not insist that python is not installed, he even accepted, but I find it strange to be so complicated to do something as simple as compiling the file for distribution. The idea of making a singular . exe is that it can be at least a little portable.
– Breno Baiardi
It’s not that it’s complicated. You don’t want to send dependency Dlls together. And if it didn’t run on Windows 7 it may be because there are some missing Dlls that your version of the OS already has (it is common to occur with the Visual Studio 2015 Redistributables, for example, that some Python libraries depend on). It would only be the case to install, if it is the ones that are missing. Anyway, it would certainly be easier to have only one exe, but then the most uncomplicated would be to use an appropriate language.
– Luiz Vieira
I tried to insert the dll manually, but it seems that the files being required (api-win-msi-crt-[...].dll) do not work in the version of windows 7 installed (without sp1) in other versions with Sp2 the program worked. When trying to upgrade the system to sp1, the computer is loading for hours and shows no progress. until the microsoft Hotfix that was supposed to fix the error did not work. The biggest problem is being the client machines with outdated system, The system is "locked" in windows 7 without even sp1.
– Breno Baiardi
It’s just that these packaging tools just pick up the Dlls in use in your system. That’s why it doesn’t work on the target system if it’s different. To solve, only if you have a similar system (that is, in the same version of Windows) and package there too. Meanwhile, consider also using Cython: http://cython.org/ to convert your Python code to C and then compile the C code into an executable. Good luck!
– Luiz Vieira
Thank you very much! I will check. one last try. :)
– Breno Baiardi
I am not a professional, but I ask for permission to tell you what I did when I played to create . exe from python programs. I downloaded the Python installation files, if I am not mistaken a minimal version and put together with the files of my program, bundled everything using INNO and configuring it to install Python too, it worked, pity that only the python files add up to close to 100Mb, but compacted by the INNO everything fell to more or less 30Mb.
– Marcio Luís
I remembered now another way I used; I downloaded the Python files, not the installer but the same files and folders and left along with my program. At INNO I configured to add an entry in the Windows registry, so that the files . py (I actually switched to an extension that does not exist in order to avoid conflicts) open with the Python executable (pythonw.exe) that is in the python folder that comes with my program. It’s kind of confusing, but it worked here.
– Marcio Luís
What went wrong with Pyinstaller? I use python 3.5 and my pyinstaller works perfectly. You can even create a file. exe single with all dlls inserted in it with Pyinstaller, instead of a folder full of files.
– Benedito
pyinstaller just doesn’t run, it doesn’t open. I followed a couple of tutorials and gave in it
– Breno Baiardi
Try py2exe 0.9.2.2. Download link: https://pypi.python.org/pypi/py2exe/
– Marcelo Zochio
Just compile what cx_Freeze generates with Iexpress. Take a look at my answer. Abs
– Guilherme IA