How do I make a python executable in Windows?

How do I make a python executable in Windows?
Answer
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’.
Code:
https://commons.wikimedia.org/wiki/File:DandEror.png
Run your script
  • Open Command line: Start menu -> Run and type cmd.
  • Type: C:\python27\python.exe Z:\code\hw01\script.py.
  • Or if your system is configured correctly, you can drag and drop your script from Explorer onto the Command Line window and press enter.
Run a Python script under Windows with the Command Prompt. Note that you must use the full path of the Python interpreter. If you want to simply type python.exe C:\Users\Username\Desktop\my_python_script.py you must add python.exe to your PATH environmental variable.Run a Python script under Windows with the Command Prompt. Note that you must use the full path of the Python interpreter. If you want to simply type python.exe C:\Users\Username\Desktop\my_python_script.py you must add python.exe to your PATH environmental variable.
This appendix will show you how to compile your .py Python files into .exe programs that can be run on Windows without having Python installed.
  • Step 1: Download and Install py2exe.
  • Step 2: Create Your setup.py Script.
  • Step 3: Run Your setup.py Script.
  • Step 4: Distribute Your Program.
The real problem is that when you run a command in any of the Cygwin terminal programs like mintty, they don’t act as Windows Consoles. Only Windows Console-based ones like CMD or Console2 do that. So, with Cygwin terminals the Windows python.exe doesn’t think it is talking to an interactive console.If Python is installed, you just need to locate path to python.exe, and add it to the %PATH% environment variable. You can run this Powershell command to find it. (Use ‘Run as Admin’ when you launch Powershell so the second command works). Just copy and paste this into your Powershell session and hit Enter.Open a command prompt window and navigate to the folder containing get-pip.py . Then run python get-pip.py . This will install pip . Verify a successful installation by opening a command prompt window and navigating to your Python installation’s script directory (default is C:\Python27\Scripts ).
Run the Python command-line interpreter, under your OS of choice,
  • Open Command line: Start menu -> Run and type cmd.
  • Type: C:\python27\python.exe.
  • Note: This is the default path for Python 2.7. If you are using a computer where Python is not installed in this path, change the path accordingly.
 

Tìm kiếm

Back
Top