Released independent programs for calling python by VC

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.