I have written a program. I don't know if it is important how it is written but you can find it here: http://pastebin.com/Z3ZvVPV8 Basically, it asks you to assign values to variables and will perform calculations depending on what variables you chose, and prints the answer.
I would like to know how I can make the program run in a window other than cmd (I am using Windows Vista 32bit). I don't need much at all in terms of GUI, just a window that is a bit more user friendly/easier to look at when they are using the program.
EDIT: To those suggesting using IDLE, while that would work for me, if others want to use the program they would have to download it, so I was hoping for a way for that not to happen.
Python comes with a sort of default GUI package TkInter you can use it.
Also there is a lot of other GUI packages available.
The Python standard library offers a lot of ways to implemt simple (but also rather complex) GUIs. I'd like to point you at the documentation of TK (tool kit for graphical interfaces) http://docs.python.org/library/tk.html where you will find also some useful example of use.
Py2Exe is a viable option if you really don't need a gui. This will make it run and look like a command prompt, but it will be an .exe file. Here is a quick quote from thier page: "py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."
Another alternative is to get Portable Python. Here is a quote from thier webpage: "Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application." After packaging the portable python and your .py or .pyc file then create a .bat file that runs the portable python "Python-Portable.exe" with the correct command line parameters for loading your script. Be sure to use relative paths in the batch file in case they are running it from a flash drive, or something other than the same location as you.
NOTE: This is really not a good way to do this as thier download page states: "Installed size: based on selected packages, between 49MB and 480MB". Also be sure to read the the current Python Software Foundation License, as that is what Portable Python is released under, and it may or may not be legal to package it in a closed source project. I haven't really looked at the license myself to be able to tell you. If you are releasing it as open source, then there would not be an issue though. As a quick side note, if you need that .bat file to be a .exe file then you can use a .bat to .exe converter battoexe.com is one. This is really going the long way about doing the whole thing, but it is an option.
Sources:
Working with Python on and off for 7 years now, a lot that using a portable version on a flash drive, and also dealing with Batch files much longer.
Related
I have written my python program with a Gui. Now i wanna use this tool in my company.
for this I need an .exe so others can use it.
I know my code. But now i have to compile my code to an .exe file with a third party tool like pyinstaller or pyuic.
How can I be sure this open source tools are safe to use in my company without risking any hackers infiltrated this tools?
Is there any official way or tool to make a usable windows program from a py file?
The "official way" to load PyInstaller is done via the pip command.
Open source does not mean everybody can edit the code that ist officialy distributed. If you would edit a copy of a printed law in your house does not mean that the law changes for everyone. Official commits are reviewed and checked against malicious edits.
Did you ever question other Python packages you loaded into your machine? They are distributed the same way.
Malicious actors will sometimes make clones of packages and publish them with a similar name in order to get lucky when people makea typo in the pip command. This is something you should always check.
I'm working on a 2d game in pygame, and I want it to be available on the web. In my head, a fun way to challenge myself is to use web assembly to make the game available on the web. So I'm wondering if there is any way to take executable binary (.exe) and somehow "compile" .wasm if that's still sayable at this point) to
Running a .exe via WebAssembly (WASM) in the browser will be extremely slow and inefficient but is still possible with a Wasm PC emulator ( eg v86 ) + an OS ( eg ReactOS ).
But if you can gain access to game sourcecode then
what you could do is using CPython 3.11 which supports WebAssembly target ( with the help of Emscripten a C/C++ compiler targeting WASM ).
Add to that the latest development version of PyGame and minor changes to the game main loop source code.
You can now run directly the game if you pack both sourcecode and assets with the emscripten File Packager instead of a .exe you will have a .wasm (cpython) + one .data (assets+code) and some javascript glue to load them.
Please note that currently there is no straightforward tool to do that at once, but situation will most likely evolve very quickly after release of CPython 3.11.
Personally, I don't have much experience with combining .py and .wasm files, but I do know some stuff regarding running Pygame:
First of all, you can run basic Pygame files here. I scoured the internet in search of an independent Pygame running engine, and this is the only one I could find.
Second, you can use PyInstaller to convert your Pygame file itself to .exe (it packages it nicely, but can't be signed, so some computers might think it's a virus). I have no idea how to run this specifically on the web, but if you can manage to find a web platform that can run it with a window, then you can maybe try and run that .exe with Javascript and connect the .wasm to that.
Third, I'm not sure there's a way to run .exe files with a separate window in web assembly, but I'm not too familiar with wasm.
I hope that helped!
We have a sizeable, legacy Python application written in Python 2.7 64 bit on Windows 10 64 bit - with GUI in wxPython, heavy numerical computations via NumPy, 2D plotting with MatPlotLib, 3D with VTK and so on, which we distribute as py2exe compiled binary after converting all our own Python files to pyd (Windows dlls) using Cython.
Since about a month ago, we started experiencing a super weird behavior of the file open dialog on Windows - i.e., a dialog that appears when the user asks to load a model/file from disk. The issue is, all the filenames are gone, we can only see the icons for folders/files, no text at all.
Please see picture below:
As you can see, the central list which usually contains icons and filenames now displays only icons. The only way to get the filenames back is to right-click in the main window and select "Refresh" - although sometimes navigating to a different folder makes the filenames show up.
This behavior does not show up while using the Python code, only in the compiled app. And it does not happen with other software (Microsoft Office, Notepad++, anything else, they all use the native Windows file dialog like our app and they all work all right).
I have been fighting with this for days and days, and it's not that obvious what is going on as the executable distribution folder has hundreds of dlls and standard Python modules and sub-folders containing the Python standard library plus all 3rd party libraries... the possible interactions between those dlls and Windows native ones are uncountable.
We also have zero control on Windows updates, when and where and how, and zero access privileges on our machines as they are locked down corporate beasts.
Now, for the questions:
Has anybody ever seen this behavior before in an app? If yes, can you point us to a possible solution?
If no one has seen this before, do you know if there is a way to force a refresh of an open file dialog, by whatever mean necessary - whether it is a MFC command, a Python one via win32gui, a system call, a C hack, anything?
Thank you in advance from a hair-pulling fellow programmer.
EDIT
After some more pain, I found out that py2exe had included a Windows DLL (PROPSYS.dll) from my machine, which was incompatible with all other machines (they have all sort of architectures). Excluding that DLL from the build system has fixed the problem.
Thanks go to #Simon Mourier for the invaluable suggestion to look at the DLL used by the process. Thank you!!! If you post your comment as an answer I’ll accept it as solution.
In Windows, when an application fails in a strange way, one idea is to check what are the .dll loaded in that application's process and try to spot anything that looks strange.
This is especially true when you use the Common Dialog (Open, Save As) provider by the Windows Shell since doing that potentially bring in a lot of 3rd parties .dll, loading them in the process.
One of the best tool to check that is Process Explorer from Sysinternals.
Here is a screenshot that shows external .dll opened in standard Notepad just because I used the File Open dialog box. We can see Intel's extensions, Adobe extensions, OneDrive, etc.
It was not the issue here, but still, it apparently helped spot the problem.
I am currently interning at a place where they've asked me to make a standalone python program to do something (say X).
Now, that program is to be run by some commands sent by their proprietary software which is written in their proprietary language. Now the reason I'm saying proprietary so many times is because they aren't ready to take me anywhere near their code. I am just supposed to make a Python code that does X based on the input given by their software.
So is there a way I can make an API and wrap it around my code so as to let the software control it? Also I need to make the whole thing standalone (maybe an installer of some kind) so that they don't have to install Python and the accompanying modules (like opencv) just to run my script?
All I could get out of them was "there are dll files that will be calling your app and we want an executable"
Any programm can execute any other program (if it has the appropriate rights) so there is no real distinction between "python file" and "python executable" (that is because python is an interpreted language. The python source files and the "final python program" are "identical" (asuming cpython), in contrast to e.g. a C program where the source files and the executable are vastly different).
If you are on windows there is the additional problem that the user must have installed python to execute .py files. There are some ways to mitigate that problem - there are python libraries that "freeze" the python interpreter and your code into a single .exe file (from the comment by Bakuriu see e.g. freeze) . You could bundle the python interpreter with your code. You can just say your users to install python (if the amount of users is low that might be the good way).
"API" is just a fancy way of saying "this is how you communicate with my programm". This might be how you call a library (e.g. what functions a python module exports) or this might be an HTTP API or which command line arguments are passed or which protocoll over an TCP socket is spoken. Without knowing which API you are supposed to implement you cannot fulfill your job.
Without knowing further specifications (what inputdoes the other program give to yours, how does it call your programm?) it's very hard to say anything more helpful.
I'm looking to be able to create an executable with py2exe or something similar that takes information from an excel sheet and returns a word file.
Since my coworkers are technically challenged, I need to create an executable that will take the work out of it for them.
Two questions here:
I have to be able to import something into the python script that represents DataNitro. What module represents DataNitro?
Is this legal? I won't be using a DataNitro license on every machine this exe will run on, besides my own, so if it's even possible, is this a bit shady?
Thank you.
P.S. If I'm not able to do this I will probably have to use xlrd,xlwt,etc.
The best way to give non-technical users access to DataNitro is to copy the VBA interface: hook the script up to an Excel button and have users press that button to run it. (There's no difference between running a Python script with DataNitro and running VBA code from the user's point of view.)
Each person using the script would need a DataNitro license.
There's no way to make DataNitro work with py2exe, unfortunately.
Source: I'm one of the DataNitro developers.