Windows installer from python source code without access to source code

Jim Schwartz jschwar at sbcglobal.net
Thu Apr 6 15:49:50 EDT 2023


I downloaded VS community 2022 and I know how to access the developer command prompt.  I'm using the one called x64 Native Tools Command Prompt for VS 2022

I ran a command to compile my python code that was converted to c with the following command:

H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>cl /O2 /I"C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\include\\" aws_pc_backup.c C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32216.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

aws_pc_backup.c
Microsoft (R) Incremental Linker Version 14.35.32216.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:aws_pc_backup.exe
aws_pc_backup.obj
C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib
   Creating library aws_pc_backup.lib and object aws_pc_backup.exp

When I ran the program, I got this, though.  Obviously, it doesn't know about the requests package.  Do I have to link something in with the executable?

H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>aws_pc_backup.exe -m:lb
Traceback (most recent call last):
  File "src\\python\\aws_pc_backup_main.py", line 7, in init python.aws_pc_backup_main
ModuleNotFoundError: No module named 'requests'





-----Original Message-----
From: Barry <barry at barrys-emacs.org> 
Sent: Tuesday, April 4, 2023 1:25 PM
To: Jim Schwartz <jschwar at sbcglobal.net>
Cc: Eryk Sun <eryksun at gmail.com>; python-list at python.org
Subject: Re: Windows installer from python source code without access to source code



> On 4 Apr 2023, at 16:28, Jim Schwartz <jschwar at sbcglobal.net> wrote:
> 
> Where can I download that cl program?  I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer.  Is that true?  

It is part of visual studio C++.
Once you have that installed there are bat files that setup environment in the terminal.
Then you can use cl, nmake etc

Barry
> 
> -----Original Message-----
> From: Eryk Sun <eryksun at gmail.com>
> Sent: Friday, March 31, 2023 12:55 PM
> To: Jim Schwartz <jschwar at sbcglobal.net>
> Cc: python-list at python.org
> Subject: Re: Windows installer from python source code without access 
> to source code
> 
>> On 3/31/23, Jim Schwartz <jschwar at sbcglobal.net> wrote:
>> I want a windows installer to install my application that's written 
>> in python, but I don't want the end user to have access to my source code.
> 
> Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally.
> For example, the following builds a "hello.exe" executable based on a "hello.py" script.
> 
>> cython -3 --embed hello.py
>> set "PYI=C:\Program Files\Python311\include"
>> set "PYL=C:\Program Files\Python311\libs"
>> cl /I"%PYI%" hello.c /link /libpath:"%PYL%"
>> copy hello.exe embed
>> embed\hello.exe
>    Hello, World!
> 
> I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use.
> 
> The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]:
> 
>    [...]
>    /* Implementation of 'hello' */
>    static PyObject *__pyx_builtin_print;
>    static const char __pyx_k_main[] = "__main__";
>    static const char __pyx_k_name[] = "__name__";
>    static const char __pyx_k_test[] = "__test__";
>    static const char __pyx_k_print[] = "print";
>    static const char __pyx_k_Hello_World[] = "Hello, World!";
>    [...]
>      /* "hello.py":1
>     * print("Hello, World!")             # <<<<<<<<<<<<<<
>     */
>      __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World);
>            if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error)
>    [...]
>      /* "hello.py":1
>     * print("Hello, World!")             # <<<<<<<<<<<<<<
>     */
>      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_,
>                                      NULL);
>            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
>    [...]
>    int wmain(int argc, wchar_t **argv) {
>    [...]
>        if (argc && argv)
>            Py_SetProgramName(argv[0]);
>        Py_Initialize();
>        if (argc && argv)
>            PySys_SetArgv(argc, argv);
>    [...]
>              m = PyInit_hello();
>    [...]
>        if (Py_FinalizeEx() < 0)
>            return 2;
>    [...]
>        return 0;
>    [...]
> 
> --
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list