Compile Python scripts to generate executableProgram, Which can be compiled using py2exe.
When calling python in VC, you can use py2exe to complete independent release of the entire program.
Google. py:
#! /Usr/bin/ENV Python
Import sys, webbrowser
Def main ():
Url = "http://www.google.com/search? Q = % s "%
Webbrowser. Open (URL)
VC source code (Python path, etc. need to be set by yourself), this program is to open Google search input keywords by calling Python
# Include
Int main ()
{
Py_nositeflag = 1; // avoid the error "'import site' failed"
Py_initialize ();
Pyobject * pmodule = NULL;
Pyobject * pfunc = NULL;
Pmodule = pyimport_importmodule ("google"); // name of the called File
Pfunc = pyobject_getattrstring (pmodule, "Main"); // name of the called Function
Pyobject * ARG;
Arg = py_buildvalue ("(s)", "look"); // constructor, Keyword: "Look"
Pyeval_callobject (pfunc, ARG); // call a function
Py_finalize ();
Getchar ();
Return 0;
}
1. Compile Google. py into executable programs using py2exe:
Slave (different scripts generate different library files ).
2. the following files are required for publishing a program compiled by VC:
Executable program: *. EXE;
DLL: python25.dll;
Python script: Google. py;
Library File: python25.zip(rename library.zipas python25.zip, the program calls the library file with this name by default ).
3. Put it in a machine without a python environment. The test succeeds.
So now, you can publish the VC program that calls python!