This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 8 years ago.
Writing some project on Python via PyCharm.
I want to get an exe file from it.
I've tried to "Save as->XXX.exe" - but ,when i'm trying to execute it there is an error "file is not supported with such kind of OS"
p.s.
i've got win7 x64,it doesn't work on x32 too.
You cannot directly save a Python file as an exe and expect it to work -- the computer cannot automatically understand whatever code you happened to type in a text file. Instead, you need to use another program to transform your Python code into an exe.
I recommend using a program like Pyinstaller. It essentially takes the Python interpreter and bundles it with your script to turn it into a standalone exe that can be run on arbitrary computers that don't have Python installed (typically Windows computers, since Linux tends to come pre-installed with Python).
To install it, you can either download it from the linked website or use the command:
pip install pyinstaller
...from the command line. Then, for the most part, you simply navigate to the folder containing your source code via the command line and run:
pyinstaller myscript.py
You can find more information about how to use Pyinstaller and customize the build process via the documentation.
You don't necessarily have to use Pyinstaller, though. Here's a comparison of different programs that can be used to turn your Python code into an executable.
Related
This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 1 year ago.
I want to execute three python script that I have developed. I found one doubt, how could I do it using a python script?
I want to convert it into a .exe, because our solution is thought to be executed in machines without python installed so having an unique script would be helpful.
Edit: I don't know the cause of the closure, I know how to use pyinstaller, my question was how can I execute 3 python using a python script or if it is possible.
Any suggestion? Thanks!
To package script and all dependencies you can use Pyinstaller, see here.
To execute multiple script (or exe) you can write a bat file that start the 3 exe or use them as services, based on your needs.
Use pyinstaller it can convert python to executables. You can get it up and running simply by doing
pip install pyinstaller
pyinstaller myfile.py
I have a python script I want to pack into .exe file for the ease of use. The python script makes extensive use of Tkinter module for nice GUI. I've packed it first into .exe using pyinstaller and the guide outlied here - https://datatofish.com/executable-pyinstaller/
I have two problems. First is that my script makes use of FlowCal module, which doesn't come with Python's pyinstaller (I've made script using Spyder, and I'm using Python 3.8. to compile using pyinstaller) - so I installed FlowCal with pip install FlowCal so Python gets it too (I think that's how it works? Not too sure). But then FlowCal is dependent on various sklearn modules, and it would be a headache to install modules, compile to exe, then check if it works over and over. Is there a way that ALL modules script uses (and ALL modules that imported modules use) are compiled into the script?
Second problem is that alongside GUI I get another window. Picture included. How do I remove that window?
Another thing you can do without any hassle is using auto-py-to-exe. This will generate .exe from .py with writing command, just clicking some buttons in a GUI. For this, you have to give the command: pip install auto-py-to-exe in command prompt or PowerShell, whatever you like most. After successfully installing auto-py-to-exe, give the command auto-py-to-exe in your command prompt. Then give the necessary informations, and get your generated executable file!
Add the missing modules to the hiddenimports
hiddenimports=['sklearn.neighbors.typedefs','sklearn.neighbors.quad_tree','sklearn.tree._utils']
Or use it when you create the exe in cmd as
--hidden-import=modulename
So basically what I'm trying to do is to download python with a python file. It needs to be so that user does not have to interact with the python installer at all. They just click the file and python is installed on the computer. I don't need pip I just need the computer to be able to read .py files. I seem to only be able to download the installer which the user then must open.
What would the solution to this be?
I'm using python 3.6. Also, the file must be able to be compiled to .exe so something built into python and not a module from the internet would be best (I sometimes have trouble compiling files with modules from the internet with pyinstaller) but I'm open to anything.
This is my first question so I might be doing something wrong...
You will want to start by developing a python script that does any function you want it to do. In this case, it looks like you want it to download python and install it without user interaction and you want to be able to run this as an executable on windows. So your process would be as follows.
your_script_name.py
This contains all the code to download and install python non-interactive.
Then to convert this into windows.exe install pyinstaller then run the following.
pyinstaller --onefile <your_script_name>.py
This will result in your_script_name.exe
Note: You need to run pyinstaller on a windows system for it to produce an .exe
My goal is to have a python script that I can giving to someone to run on their windows machine that does not have python installed. I do want to package it up in an exe because I want the underlying code to be easily read.
I am updating an old VBscript and I want to mirror it. I am also using a few libraries.
use pyinstaller to package it up to an exe. You can still maintain your source code. Packaging it up wont remove your source code.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Set up Python on Windows to not type python in cmd
When I use python on Linux, or even Mac OS from command line, I take advantage of the shebang and run some of my scripts directly, like so: ./myScript.py. I do need to give this script executable permissions, but that is all.
Now, I just installed Python 3.1.2 on Windows 7, and I want to be able to do the same from command line. What additional steps do I need to follow?
This sums it up better than I can say it:
http://docs.python.org/faq/windows.html
More specifically, check out the 2nd section titled "How do I make Python scripts executable?"
On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to make scripts executable from the command prompt as foo.py. If you’d rather be able to execute the script by simple typing foo with no extension you need to add .py to the PATHEXT environment variable.