2019-03-17 00:58:07

So I've been working on something for a few weeks and I believe it's ready to see the light of day, not by the community, but for me. Trouble is, I don't know how to create an executable. Googling "creating an executable in python" Brought me to py installer. Here's a thing, when I run the commands I get about 7700 of characters warning me about not finding this or that module. It gets so bad that pressing enter on the supposed executable just brings in fatal error, which crashes and screws off. So, help? I'm really getting tired of asking. How do I set the paths for the script? Is there a nicer thing out there that all of you use to create your compiled code?

2019-03-17 01:26:15

hello there!
First, congratulations for plucking up the courage to use python, I respect you right away.
Second, lets talk about pyinstaller, your new best friend.
First things first, don't compile your program into a .exe file until you know it works.
So, instead of running pyinstaller myprogram.py
run: python mypogram.py
this will tell you all of the problems you have.

Done that already? Fantastic!
Lets talk about a few things about pyinstaller. Here is what I use to compile my python programs:
1, if its in development:
pyinstaller program.py --onefile

2. If its not:
pyinstaller program.py --onefile --windowed.

But what does this mean?
--onefile: this means compress my project into one file only.
--windowed: This means make sure that, when the program is run, the python window is hidden.

So, why exclude off windowed when in development?
Because then you can run your pyinstaller, then do cd dist, and then program.exe

that way, if your program freezes, tracebacks or errors, you can see why it did and what the problem is.
GOOD TIMES!

A note about certain modules:
Certain modules, such as accessible_output2, and sound_lib may require you to copy them into the dist folder, I recently discovered a way in which you can write it into the specfile to make it compile them in, but that's a story for another day.

Hope this helps, and my pm/email is open to further assistance if you so need.
My greatest respect for using python

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2019-03-17 01:54:02

It worked! Thank you! Now why can't google provide that answer?
Is there a way of moving the required folders into it as the dist is created? I had fatal errors until I realized that... I didn't have my sounds in the folder.
Is there also a way to write that fatal error to a file?

2019-03-17 02:01:43

That is where specfiles come into play.
If you open program.spec you will see a line that looks like this:
datas=[],

If you change that to this for example:
datas=[["sounds/*", "sounds/*"]],

It will ensure your sounds folder, and  subdirectories or files are included into your .exe file.
simply save the file, then run pyinstaller program.spec to recompile.

this is explained further here:
https://pythonhosted.org/PyInstaller/spec-files.html

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2019-03-17 04:57:26

Hi,
How can we make sure our code is 100% protected, as much as a developer can make it using pyinstaller etc?
The last thing I wanna hear is that somebody used pyinstaller extractor and got my source code...

2019-03-17 05:12:09

The only you can do this is to cythonize your code. Cythonization involves a program called cython, which takes python code and translates it into C code which is then compiled and linked into your executable. I'm not too sure on how you actually do it, but I know that Carter's done it.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-03-17 05:31:41

Yep, Cython is probably the only way to do so, and even this is still no 100% guarantee, since its still a Python interpreter required to run the code and there are ways to hack and retrieve code by manipulating the Python interpreter. But if you don't use Cython or some other transpiler to secure and speed up stuff, you'll always be able to read the byte code from within the executable or library zip file and thus get at least the byte code of your source code. There is almost no way around that when using Python. Python is just interpreteted and all interpreted languages are unsafe compared to directly machine-interpreted code.
Best Regards.
Hijacker

2019-03-18 18:06:02

This is interesting, I didn't know that pyinstaller can bundle files that you want it to, thanks!

2019-03-18 18:48:45

Hi there.
To cythonize and link your program in a protected executable, you will need to create a launcher program.
The launcher program is the entrypoint of the app it's self, for this to work your application needs to have a function called main() or start() which is called from the launcher.
In the launcher you basically import all the libraries used in the program (use the one you've cythonized) and run the entrypoint function.
You could improve the launcher by doing a try except block which writes errors to the file.
Note that in some cases your executable will be extremely large because pyinstaller has a thing called hooks.
Hooks allows you to import other libraries without needing to put the code in the application folder and sometimes numpy will beincluded in your executable because of them. If that happens, just delee the numpy hooks, which is in python\lib\site-packages\pyinstaller\hooks

Paul

2019-03-18 19:09:43

@9, so let me see if I understand this:
1. Cythonize your code into C/C++
2. Compile it into a DLL (yes/no)
3. Create a launcher with a function called main and import my compiled DLL as the only library
Is that right?

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-03-18 19:39:13

@10
You cythonize the modules you need and you will have a .pyd file on windows. I forgot the extension on linux.
But in my case the file looks something like this:
interface.cp37-win32.pyd
interface is the module I've cythonized. Once that's done in the launcher script import this file. Make sure it's the pyd not the original.
Then run pyinstaller on the launcher.
Sorry, my english is extremely bad, so let me know if I should provide an example.

Paul

2019-03-19 18:18:21

I need some kind of compiler to use cython it seems. I'll have to try home

2019-03-19 18:23:56

wait, so py py doesn't let you go into the context menu and hit compile on a .py file? Bad py py!

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-03-19 18:32:40

Hi, i don't know what is going on with python, or should i say pyinstaller.
I say pyinstaller game.py --onefile --windowed
it compiles but when i launch the game, it gives me that faitle error thing. but before compiling the script, i did:
python game.py, worked through the game and saw no error.
what could the problem be? all the required data files are in the game's folder.

best regards
never give up on what ever you are doing.

2019-03-19 20:30:47

@14, how are you launching your pyinstaller? Here's what I do:
1: Go to the folder with my scripts.
2: Press alt
3: Hit down arrow twice and press enter. This in turn will open the cmd that already is in your script folder.
4: type pyinstaller myscript.py --onefile --windowed.
I'm on windows 8, however, so the instructions may not apply if you're on something like 10.

2019-03-19 20:41:30

that is exactly what i do.
In other words, i use the file exploarer to navigate to the folder with my script.py, go to the command prompt and cd to myscript folder, pyinstaller --onefile --windowed... same resault. i am not even using an external library. that confuzes me a lot. if i was using an external library, it was another story...

best regards
never give up on what ever you are doing.

2019-03-19 21:36:34 (edited by magurp244 2019-03-19 21:36:42)

Is it a specific traceback error? Could you post it? When you run a compiled pyinstaller exe it unpacks it into a temporary folder on C drive, sometimes you can get linking errors when your scripts go looking for files which might be either in the temp folder or the script folder, depending on where the working directory is, among other things.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-03-19 21:38:03

Hi, @17, i don't even get a compelation error at all. it only tells me faitle error trying to launch the script...

best regards
never give up on what ever you are doing.

2019-03-19 22:53:18

try compiling without windowed and see if it gives you any traceback? For this to happen run from the commandline the executable.

Paul

2019-03-19 23:23:54

when compiling without windowed, it works 100 percent fine.

best regards
never give up on what ever you are doing.

2019-03-20 16:46:46

Can someone tell me what I need to install to compile .pyd files with cython?
Sooner or later it encounters an error.

2019-03-20 16:57:50

install cython and the visual c++ compiler. You can install the desktop development with c++ from Visual Studio

Paul

2019-03-20 19:53:14

Umm, thanks... Note to self: Download 3 gb of stuff and see which part works.
I downloaded various packages already and nothing worked.
Can you please post a link to the exact persion? I got Python 3.7.2

2019-03-20 20:13:32

just type pip install cython. It should work

Paul

2019-03-20 20:55:21

So if I make a cython file and then use pyinstaller to create an exe, would I get 1 file? Or would the cython file be left alone and accessible to anyone?