How to minimize python installation on the client and minimize python on the client

Source: Internet
Author: User

How to minimize python installation on the client and minimize python on the client

Because we want to add python support to our desktop software, we want to simplify the python library and put it directly on the client and under our directory to avoid unnecessary things, do not affect the machine. However, after the program is written to the test machine, the old hacker cannot find the no module named site. Then, he can check the code and finds that the database site cannot be found, this library is also required for python initialization. solution:

1. Try to put the Lib in python on my computer into the program directory on the client and create a python27/lib/. The result is still failed.

2. put the items under lib in the same directory as the exe. Yes, but who still displays the import pbk_resource error, but you can run the python interpreter, however, this method is not recommended because it is too complex in the same directory as the exe.

 

 

 

Later I checked the Py_Initialize code and found that python looks for lib like this when no PYTHONHOME is set:

The following code

 

 if (pythonhome == NULL || *pythonhome == '\0') {        if (search_for_prefix(argv0_path, LANDMARK))            pythonhome = prefix;        else            pythonhome = NULL;    }    else        strncpy(prefix, pythonhome, MAXPATHLEN);

 

1. When pythonhome is NULL, the python initialization function calls search_for_prefix to set the default home

 

static intsearch_for_prefix(char *argv0_path, char *landmark){    /* Search from argv0_path, until landmark is found */    strcpy(prefix, argv0_path);    do {        if (gotlandmark(lan dmark))            return 1;        reduce(prefix);    } while (prefix[0]);    return 0;}

 

2. landmark is a string containing lib/OS. py. gotlandmark mainly tests whether lib/OS. py exists in the current directory.

 

/* gotlandmark only called by search_for_prefix, which ensures   'prefix' is null terminated in bounds.  join() ensures   'landmark' can not overflow prefix if too long.*/static intgotlandmark(char *landmark){    int ok;    Py_ssize_t n;    n = strlen(prefix);    join(prefix, landmark);    ok = ismodule(prefix);    prefix[n] = '\0';    return ok;}

 

3. If no, search for a directory above and continue step 2 until the directory is found or the prefix [0] is 0.

 

So we only need to test the lib under python27 to the exe directory on the client.

 

After you run the test program again, it will be normal. The next step is to streamline the database. You can simply delete the databases such as test, unittest, and email.

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.