Home > other >  How to create standalone python interpreter .exe
How to create standalone python interpreter .exe

Time:10-18

can someone please help to explain how we can create a standalone python interpreter (single file like py_interpreter.exe) with all the package installed in the pc.

Background of story: I need to run my program (scripts.pyc) on a pc where python is not installed. So I want to run my .pyc file using the portable py_interpreter.exe.

I will use the batch script to run .pyc script. @echo off cls

set CWD_PATH=%~dp0

"%CWD_PATH%\py_interpreter.exe" "%CWD_PATH%\scripts.pyc"

if %ERRORLEVEL% NEQ 0 pause

Sorry if my question is really stupid

CodePudding user response:

You can check out pyinstaller project.

If you do not need console to be shown while running the produced binary,

pyinstaller  --noconsole --onefile src\script.py

if you need the console to be shown, just remove the --noconsole option. The executable would be created under the dist folder if everything goes well.

CodePudding user response:

if you want to obtain a .pyc so that you re-use it, then:

import py_compile   #just import this line
py_compile.compile('yourFile.py')

# Find you "compiled file (.pyc)" saved ...yourfile.pyc in a __pycache__ folder, (located in the same folder) as yourfile.py

Now you can use them as compiled scripts , you can even test them python yourFile.pyc & they work !

  • Related