Compile the .pyw file so that it can be run as .pyc without a console

I am trying to compile a pyw file in pyc without a console. When I try to do a direct compilation with it, the result is a pywc file, but it seems that pythonw.exe is not registering this extension as one of its files, such as python.exe for pyc.

The result is that if you try to simply execute the handler without double-clicking, or if you change the extension to pyc, you will get a console.

Does anyone know a way to solve this problem? Will something affect .pyc without a console?

Thanks!

Update: Since running this via execfile or double-clicking on the icon in the windows does not create a compiled version of this file, I run python on the command line and then:

import py_compile
py_compile.compile("[FileName].pyw")

Here I get the extension .pywc. My Python version is 2.5.4

+3
3

( OP)

*.pyc *.pyo , *.pyw, .

, main.pyc main, top.pyw, :

# top.pyw file
import main
if __name__ == "__main__":
    import sys
    main.main(*sys.argv[1:])

main.py :

# main.py file
"""
Main module documentation (optional)
"""
# import modules

# function and class definitions

def main(*argv):
    # Parses the options (optional)
    import optparse
    parser = optparse.OptionParser(usage="%prog [<options>]\n" + __doc__)
    parser.add_option(...)
    parser.add_option(...)
    opt, args = parser.parse_args(list(argv))
    # Calls the appropriate function:
    my_function(...)

, *.pyc . , pyInstaller "" .

Edit = > , pyInstaller, , Python, (-w ). . , , .

, , : , - -, , . , SO (, ). , , .

+5

FTYPE ASSOC .pywc pythonw.exe.

ASSOC , FTYPE , . :

C:\Python26>assoc .py
.py=Python.File

C:\Python26>assoc .pyc
.pyc=Python.CompiledFile

C:\Python26>assoc .pyw
.pyw=Python.NoConFile

C:\Python26>assoc .pywc
File association not found for extension .pywc

, :

C:\Python26>ftype Python.CompiledFile
Python.CompiledFile="C:\Python26\python.exe" "%1" %*

C:\Python26>ftype Python.NoConFile
Python.NoConFile="C:\Python26\pythonw.exe" "%1" %*

, , .pywc Python.NoConFile :

assoc .pywc=Python.NoConFile
+3

An interpreter that reads files .pywcan also read a compiled .pycpython-based file . Just rename the file .pycto .pyw. It will start (although it will still match the version) and you won’t get an ugly console.

+3
source

Source: https://habr.com/ru/post/1722162/


All Articles