Py2exe executable shows black command line window - python

There was a simple task - well, in Python it took around one hundred lines of code (the task was only to ask users for input files, process them and write results on disk). But the requirement was that it must be executable on PCs without Python interpreter. I used py2exe to make an executable file (it has increased the size from 3Kb to ~12 Mb but doesn't really matter).
The problem is - when one tries to run this *.exe, it shows black command line window for half a minute and only after that - file-selecting dialogue. Is there a possibility to get rid of that half-minute delay? Of maybe there are other .py to .exe converters which would suit better in this situation?

In py2exe
console = ['yourscript.py']
will generate a command window, use the following instead
windows = ['yourscript.py']
http://www.py2exe.org/index.cgi/ListOfOptions

This is perfectly normal when making exe files with Python code. When you make an executable file, Python itself is bundled into the .exe. This is so the user does not have to install Python on their machine to make it work. Python is an interpreted language and requires the interpreter to be bundled.
You could always try using alternatives to see if the compression rate is smaller, but chances are, its not a big deal.
If it is the code that is taking a long time, you may consider posting your code on Stack Exchanges' Code Review to see if there is anything that could be improved.
Further, if you are using Python 2.7, you should consider checking out PyInstaller. It is surprisingly easy, however, it has a couple of problems - especially with the PySide Framework - works great for plain PyQt though.
pyinstaller myscript.py --name="MyApp" --onefile
However, for a full list of optional parameters you should really check out the documentation.

Related

running a python script when i turn my pc on

I created a python script to control the RGB of my keyboard and my mouse and i want it to start when i turn my computer on. I have 2 solutions but i don't know which is the best.
the first solution is to build my script and run the executable on startup
the second solution is to run directly the python script with python.
the first solution is a little bit annoying because is i want to change the code, i need to rebuild my script. and also when i tried to run the exe (created with pyinstaller), it didn't work (because of the dlls i think)
the second solution is better if i want to change the code later, but i don't know how it would react if i run another python script (i don't even know if it's possible to run 2 python instances at the same time.)
so if you have any idea on which solution to choose, how to build a script using dlls with pyinstaller or if i can run multiple python instances (maybe i can run multiple venvs), feel free th help me.
PS: I tried to be clear but as i didn't speak english very well i don't know if you understood my issue.
Using windows : https://www.geeksforgeeks.org/autorun-a-python-script-on-windows-startup/
Using Linux : follow this https://stackoverflow.com/questions/24518522/run-python-script-at-startup-in-ubuntu#:~:text=Put%20the%20command%20python%20startuptest,and%20put%20the%20command%20there

Running Python Scripts Outside of IDLE

1- i want someone to help with this part
https://automatetheboringstuff.com/appendixb/
about Running Python Scripts Outside of IDLE and sending command line args .
2- i converted my code to .exe by pyinstaller ; what's the difference between this and running it
as a script .
3-how scripts are done . i see experienced people says :"i made a script to do something for me " how is that done >?
*i'm a beginner so try to make answers simple as possible.
If you're wondering about command line arguments, look into the "argparse" library https://docs.python.org/3/library/argparse.html.
The difference in the .exe and the normal script is that that the .exe versions (conventionally) are able to be redistributed to other sytems that don't have python installed whilst still being able to run the script. If you're only making the script for yourself the only real benefit is that you dont have to enter your IDE (code editor) every time you want to run the code, however if it's still in development then you'd have to compile the code every time you made a modification if you're wanting to run the code as an executable, which is very impractical.
Your third part is very, very vague. Python can be very versatile and i recommend you continue looking at the automatetheboringstuff.com website if you're interested in making scripts that can complete repetitive activities (although i must strongly advise you against using scripts maliciously).

visual studio code equivalent of python -i

I am looking for the equivalent of python -i in VScode.
That is, a way to open a terminal (or run in the included terminal) the program that is open, and use the program in the read-print-eval loop, being able to call functions and inspect variables freely.
I searched for this plugin without success.
I need it to be around as simple as pressing f5 and typing something. I want to use it to teach, and my students already have many difficulties with algorithms and coding. Also, easy instalation would be ideal. I am sorry for being that 'demanding', but classes are huge and the chance of getting everyone to do a procedure go down fast with the size of the procedure.
I would not mind creating such a utility myself, if someone will point me the way, and then uploading it to whatever 'store' VScode downloads its plugins from.

Issue with Python Batch file to run Python through Notepad++

EDIT: The code I wrote in my Python file was just this:
print "foo"
I'm using Windows XP Home Premium on this tiny little HP Mini 1000, and I want to run Python files, since we're learning it in school. I am aware of this topic, so I tried to run Python files using a batch file (python.bat), and I'm getting an error that says, "Can't find 'main' module in ''" whenever I run the batch file. I followed the instructions given here. All I did was change "Python26" to "Python33" because of the difference in versions.
Any idea what's wrong here? I really want to run Python files from Notepad++, so I don't want any alternative ways to run them.
This sounds like you don't have PYTHONPATH set up correctly. I suggest you review the documentation here:
http://docs.python.org/2/using/windows.html
Instead of calling Python, call cmd.exe and then use the set command to inspect which variables are set and how they are set. Run the exit command to leave the command shell. When you think you have the variables set up correctly, try again to run Python.
Good luck and have fun!
I use the command line interpreter or IDLE mostly (Win 8.1 now, but I've done so since Win XP SP2), but NPP is my main text editor, so I was curious about this issue.
When I was reproducing this, I was able to generate several errors, but the only one I got that was an exact match was when I failed to configure the Run option correctly.
You need to make sure to follow this step exactly in the instructions you were following. When you navigate to Run -> Run in Notepad++, you have to enter this exactly:
C:\Python33\python.bat "$(FULL_CURRENT_PATH)"
I am pretty sure you left out the "$(FULL_CURRENT_PATH)", or otherwise didn't add it correctly, as failing to do so causes exactly the same error on my end. Failing to include this means that when you run the batch script, you get the wrong input to the Python interpreter, causing the error.

Distributing python-written executable with veusz

I would like to distribute an application written in python as a .exe file. I have already been able to do this using py2exe, but now I have incorporated the veusz library into my code. Ideally my program should open up a veusz plot (as it does on my computer, which has python, numpy, etc. all installed). However, I want to distribute an executable that does this without having to install python.
When I try running my setup.py with py2exe, everything goes fine and the exe is built. However, once the application runs and gets to the point where it is to display the graph, it sends up:
Runtime error: Unable to find veusz executable on system path.
Can I fix this without having to install a bunch of stuff on my clients' computers? Is this possible? And if I must install something, what is the minimum amount of software I need to install?
Veusz runs its user interface in a separate python process so that it does not block python. If you look at veusz/embed.py, it tries to start up python or a veusz executable. You'd need to modify embed.py to start your .exe (sys.executable) if frozen instead of veusz and pass some special parameter which your program would interpret to start running veusz.embed_remote.runremote.
The python multiprocessing module has to do something similar - you need to call a multiprocess function which checks whether the program was starting by multiprocessing - to get around the fact that Windows doesn't have a working fork.

Categories