A, pythoninstaller package python project
Premise: install python3.6 environment + pycharm
1. Install pyinstaller
pip install pyinstaller
2. cmd into the python project directory execute the following command
pyinstaller -F test.py
3. The following prompt appears, it indicates Packaging Success
15977 INFO: Building EXE from EXE-00.toc completed successfully.
Complete package, test.exe file dist folder under the current project directory
Two, c # call the exe file
a using System.Diagnostics; ······ // String = debugpath System.Environment.CurrentDirectory; // Debug This file c # project folder path String pyexePath = @ " F: \ · · · \ dist \ test.exe " ; // path where the python file, generally do not use absolute paths here only as an example, the proposed move to the next debug folder Process the p- = new new Process (); p.StartInfo.FileName = pyexePath; // need to do file path = p.StartInfo.UseShellExecute to false ; // necessary p.StartInfo.RedirectStandardOutput = to true ; // output parameter set p.StartInfo.RedirectStandardInput =to true ; // passing parameters set p.StartInfo.CreateNoWindow = to true ; // p.StartInfo.Arguments = ""; // parameters separated by spaces, if a parameter is empty, you can pass "" p.Start (); String the output = p.StandardOutput.ReadToEnd (); p.WaitForExit (); // key, wait for external program to perform down after exiting} Console.Write (the output); // output p.Close ()
· ?????
Bonus: pyinstaller relevant parameters
-F, -onefile pack a single file, if your code is written in a .py file, you can use this, if it is more than .py files do not use
-D, -onedir package multiple files in the dist generate a lot of dependent files, tools for writing code to form the framework, I personally recommend this, the code is easy to maintain
-K, -tk included in the deployment of TCL / TK
-a, -ascii does not include encoding. Unicode support on the python version the default includes all the coding.
-d, -debug generate debug version of the executable file
-w, -windowed, -noconsole use Windows subsystem execution. when the program starts does not open the command line (Windows only valid)
-c , -nowindowed, -console
using the console subsystem execution (default) (valid only for Windows)
PyInstaller -c xxxx.py
PyInstaller xxxx.py --console
-s, -strip executables and shared libraries will run through strip. The strip Cygwin attention often makes ordinary win32 Dll can not be used.
-X, -upx if UPX installation (detection execution Configure.py), will perform compression file (DLL Windows systems will also) (see note)
-o DIR, DIR = -out specified build directory spec file, if not specified, and the current directory is the root directory PyInstaller will automatically create one for output ( spec and resulting executable file) directory. If not specified, and the root directory of the current directory is not PyInstaller, it is output to the current directory.
-p the DIR, the DIR = -path introducing path disposed (and similar results using PYTHONPATH ) You can use a path delimiter (Windows use a semicolon, Linux use a colon) split, specify multiple directories. You can also use multiple -p parameter to set import multiple paths, so pyinstaller find their own program requires resources
-icon = <fILE.ICO>
will be added as a resource file.ico executable file (only valid for Windows systems), changing the program's icon pyinstaller -i ico path xxxxx.py
-Icon = <FILE.EXE, N> file.exe the n-th icon to add a resource executable file (only valid for Windows systems)
-v FILE, FILE = -version will verfile as the version of the executable file resources (only valid for Windows systems)
-n nAME, -name = nAME optional items (spec generated) name. If omitted, the first script file name as the primary spec name