uses Python's exec
statement to make it easy to execute Python statements dynamically. If a python code is packaged for EXE, its original code is hard to change. A good solution is to import the corresponding library and then place the main program segment in a separate file to be executed by exec
.
Now packs a simple Python interpreter, because it is an example that calls only one NumPy library.
import numpy as npif __name__ = = ' __main__ ': with open (' Cod e.py ', ' r+ ') as F:code=f.read () exec (code)
- code.py interpreted content
Code>a=np.array ([i=0for]) print (a) I in range (+): I+=iprint (i) Print (eval (' 1+2 ')) with open (' Run.cmd ') as F:pri NT (F.read ())
With Pyinstaller
package:
pyinstaller-f-C main.py
execution, we see that
can run as long as it is using a module that has been transferred into main.py (or a module alias). This achieves the effect of the wrapper interpreter .
Package A Python interpreter