Tag Archives: exe

Error reporting processing of pyinstaller packaging geopandas environment

Article catalog

1. Iteration error of geopandas occurs when executing exe. 2. Fiona cannot be found when executing exe_ Shim3. Cannot find fiona.shema4. Summary by executing exe

First, use pyinstaller – F main.py to package the code into an EXE with a black window. The following are some problems and solutions

1. The iteration error of geopandas occurs when executing exe

The error information is as follows:

(gis_data_process) D:\code\gis_data_processing>main.exe
Traceback (most recent call last):
  File "main.py", line 10, in <module>
    from gis_data_process import *
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "gis_data_process.py", line 7, in <module>
    import geopandas
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "geopandas\__init__.py", line 17, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "geopandas\datasets\__init__.py", line 6, in <module>
StopIteration
[24328] Failed to execute script 'main' due to unhandled exception!

The solution is as follows:

    comment geopandas\__ init__. Py line 17 code “import geopandas. Datasets # noqa” delete the build, dist and spec files generated by packaging and reuse pyinstaller – f main. Py packaging

    2. Execute exe and cannot find Fiona_ shim

    The error information is as follows:

    (gis_data_process) D:\code\gis_data_processing>main.exe
    Unhandled exception in thread started by <bound method GISDataProcess.generate_file_execute of <__main__.GISDataProcess object at 0x0000021A0C5D8DC8>>
    Traceback (most recent call last):
      File "main.py", line 156, in generate_file_execute
        generate_shapefile(file_path, shape_path)
      File "gis_data_process.py", line 172, in generate_shapefile
        kml_to_shapefile(kml_path, shape_path)
      File "gis_data_process.py", line 417, in kml_to_shapefile
        geojson_to_shapefile(geojson_path, shape_path)
      File "gis_data_process.py", line 220, in geojson_to_shapefile
        geometry = geopandas.read_file(geojson_path)
      File "geopandas\io\file.py", line 166, in _read_file
      File "geopandas\io\file.py", line 81, in _check_fiona
    ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
    Importing fiona resulted in: No module named 'fiona._shim'
    

    The solution is as follows:

      find the. Spec file generated by packaging, find hiddenimports, add “Fiona. _shim”, delete the build and dist directories generated by packaging, and use pyinstaller main.spec to package and generate exe

      3. Fiona.shema cannot be found by executing exe

      The error information is as follows:

      (gis_data_process) D:\code\gis_data_processing>main.exe
      Unhandled exception in thread started by <bound method GISDataProcess.generate_file_execute of <__main__.GISDataProcess object at 0x00000220B655B5E8>>
      Traceback (most recent call last):
        File "main.py", line 156, in generate_file_execute
          generate_shapefile(file_path, shape_path)
        File "gis_data_process.py", line 172, in generate_shapefile
          kml_to_shapefile(kml_path, shape_path)
        File "gis_data_process.py", line 417, in kml_to_shapefile
          geojson_to_shapefile(geojson_path, shape_path)
        File "gis_data_process.py", line 220, in geojson_to_shapefile
          geometry = geopandas.read_file(geojson_path)
        File "geopandas\io\file.py", line 166, in _read_file
        File "geopandas\io\file.py", line 81, in _check_fiona
      ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
      Importing fiona resulted in: No module named 'fiona.schema'
      

      The solution is as follows:

        find the. Spec file generated by packaging, find hiddenimports, add “Fiona. Schema”, delete the build and dist directories generated by packaging, and use pyinstaller main.spec to package and generate exe

        4. Summary

        After the above three steps are completed, you can successfully package into exe, but opening exe has a black window. You can change console = true to console = false in the spec file, and then use pyinstaller main.spec to package and generate exe, so that there is no black window

Go compiles the EXE executable to remove the CMD window at run time

         Recently, I started to contact go language again and wrote an EXE executable program. However, such a console window will appear every time I execute it, and there is no content yet. It’s not elegant, of course.

We can solve this problem by setting compilation parameters in go build

go build -ldflags "-s -w -H=windowsgui"

-s Omit the symbol table and debug information
-w Omit the DWARF symbol table Omit the DWARF symbol table
-H windowsgui does not print messages to the console (On Windows, -H windowsgui writes a "GUI binary" instead of a "console binary."), so there is no cmd window

In this way, the EXE program generated by go compilation can run in the background.

Making Python script into exe command under Windows

Making Python script into exe command under Windows

Method 1: use windows batch processing (Windows command script)

    create a new fanyi.bat file, which is as follows.

    @echo off
    python3 D:\test\fanyi.py %1
    
      add the current folder to the environment variable, re open a CMD window, and enter the command Fanyi Hello

      The second method uses pyintaller module to generate EXE file

        install pyinstaller module

        pip install pyinstaller
        
          enter the D: [test directory, and execute the generate command

          pyinstaller fanyi.py
          

          Generated fanyi.exe The file is in the D::

            add the folder to the environment variable and execute the command in CMD

0xc0000005: an access conflict occurred while reading location 0x00000020

0x in.exe… Unhandled exception at: 0xC0000005: Access conflict occurred while reading position 0x00000020

Error: : PostMessage (AfxGetMainWnd () – & gt; M_hWnd, UM_XX, 0, 0);

or: : sendMessage (
AfxGetMainWnd()-> M_hWnd, UM_XX, 0, 0);

How to solve it?
Verify that afxGetMainWnd () returns NULL

int k = (int)(& (((CWnd*)NULL)-> m_hWnd));
The value of k is 0x20

In general: afXGetApp ()-> GetMainWnd (); AfxGetMainWnd() is used only on the main thread;

How: foreground thread and background thread, afxGetApp ->; GetMainWnd() differs from AFXGetMainWnd ()

AFXGetMainWnd () is an example of a window handle that can be used to retrieve a window handle. AFXGetMainWnd () is an example of a window handle that can be used to retrieve a window handle. Clever you must have already understand, if you have been tracking AfxGetMainWnd () call, will find that it earned a AFX_MODULE_THREAD_STATE threading module save active threads in the window handle, and a background thread since no window, then obtains the window handle is you from??(maybe someone’s understanding of the background is not display window, even with all the window, as long as it doesn’t show is a background thread, strictly speaking is not the case, the window is mainly used to interact with the user, a window is hard to avoid jam, And the background thread is often used to carry out some behind the operation or processing, is through the foreground information or data to carry out the corresponding operation, if the window is hidden to talk about what information transfer?The case can not be done in the background like other threads. The key is to know the difference and how to use it.)
AfxGetApp()-> GetMainWnd () is the main window handle, no matter in that thread calls are no problem, because it is first obtained the main thread handle, to achieve the main thread of the active window (such as switch view can lead to replacement, I am not sure this kind of circumstance), if there is no active window is the main window, any program must have a main window, so it calls there is no problem, if you want to achieve the program’s main window suggested AfxGetApp () – & gt; GetMainWnd().
Note that the console program has no window and its window handle is always 0. Second, the background thread is actually a desktop control program, just not the main thread. Also, threads created using functions such as API CreateThread cannot generate CWinThread objects. So if you want to use CWinThread object function, and some of the global function, as AfxGetMainWnd (), you must use CWinThread object CreateThread function, or use the AfxBeginThread () function creates a thread, or may be an error, because the MFC to the management of the thread is done through the CWinThread object, it is not hard to see through the tracking code below you. I remember that there was a predecessor once mentioned this problem, but I do not know whether it understands the reason
Here is the trace code:
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
{ CWinThread* pThread = AfxGetThread();
return pThread! = NULL ?pThread-> GetMainWnd() : NULL; }

CWinThread* AFXAPI AfxGetThread()
{
// check for current thread in module thread state
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
CWinThread* pThread = pState-> m_pCurrentWinThread;
// if no CwinThread for the module, then use the global app
if (pThread == NULL)
hread = afxGetApp ();
return pThread;
}
You can see that calling afxgetMainwnd () on the main thread is not a problem (except for console programs) because it returns the main thread handle if the fetched thread handle is empty.
_AFXWIN_INLINE CWinApp* AFXAPI AfxGetApp()
{ return afxCurrentWinApp; }

CWnd* CWinThread::GetMainWnd()
{
if (m_pActiveWnd ! = NULL)
return m_pActiveWnd;// probably – place in active
// when not inplace active, just return main window
if (m_pMainWnd ! = NULL)
return m_pMainWnd;
return CWnd::GetActiveWindow();
}
I don’t need to worry about AFXCurrentInApp.
Hey hey, all finished, if your program exists similar to the above problems can be sure to change back oh.

Configure QT designer in pychar

Then configure Qt Designer in Pycharm
1. First install Qt and Qt Dsigner PIP Install PyQt5 PIP install PyqT5-Tools

5 in pycharm is D:\anaconda3\Library\bin\designer. Exe means the path to install designer.
do not know their own installation path:
win+s
enter designer, right click display path can

and then configure:

3 D:\anaconda3\Scripts\pyuic5 exe the same for their own installation program path
4 for:

F

i

l

e

N

a

m

e

FileName

FileName-o

F

i

l

e

N

a

m

e

W

i

t

h

o

u

t

E

x

t

e

n

s

i

o

n

FileNameWithoutExtension

FileNameWithoutExtension. Py
click ok below.


Python packaged *. Exe is running os.popen (cmd)/ subprocess.Popen *. Exe crashes with invalid [winerror 6] handle

Summary of the problem: last week I used Python3.8.5 to write an upgrade script for a software running on Windows 7, and by printing and exception catching found that the script crashed when the script was executed to os.popen(CMD), the exception was [WinError 6] handle invalid

Part of the test code:

logging.info('__Start__')
logging.info('os.system1')
logging.info('os.popen1')
try:
    logging.info(os.popen('c:'))
    logging.info('os.popen2')
except Exception as a:
    logging.info(a)
    logging.info('os.popen3')
logging.info('os.popen4')

Effect :

After testing, it was found that the program and script could run normally on Win10, and the script was executed separately on Win7 without any problem, and the script was called with the program on Win7, even if the script was executed OS.popen (‘ c: ‘) would crash.

Because os.popen is actually the encapsulation of subprocess.Popen, so the title also carries subprocess.Popen
solution: to implement a function myPopen, or use subproce. popen0 will be 1 stdin = Subprocess. DEVNULL to modify, the code is as follows:

def myPopen(cmd):
    proc = subprocess.Popen(cmd,
                            shell=True,
                            stdout=subprocess.PIPE,
                            stdin=subprocess.DEVNULL)
    return proc.stdout.read().decode()

Python running as Windows Service: OSError: [WinError 6] The handle is invalid
Popen(

Package python3.1 + PyQt4 into exe

There are many programs that package Python as an exe, such as Py2exe, PyInstaller, and so on, but so far none of them support Python 3.1 well, so I’ll introduce CX_freeze 4.2.2 here, which also supports cross-platform running on Windows and Linux.
Cx_freeze download site is http://sourceforge.net/projects/cx-freeze/files/, want to undertake choosing according to install python version. For example, I am using python3.1, so I will download the file cx_Freeze- 4.2.2.2.win32-py3.1.msi. After running the installation package, the program is copied to the Python directory. There are two main places, one is C:/Python31/Scripts and the other is C:/Python31/Lib/site-packages/cx_Freeze
 
In previous versions of cx_Freeze, py was converted to exe through the script Freezepython.py, but in 4.2.2 Freezepython.py is gone and the main work is done by the C:/Python 31/scripts cxfree.bat.
There are two main ways to complete python exe packaging using cx_Freeze:
First, run cxfreeze. Bat directly through:
Go to the CMD command line, enter the C:/Python 31/scripts directory, and run cxfreed.bat-h to see its instructions. We can do an experiment with CX_freeze’s own sample.
Go to C :/ Python 31/scripts/ and run
cxfreeze C:/Python31/Lib/site-packages/cx_Freeze/samples/PyQt4/PyQt4app.py –install-dir=d:/123
Pytqt4app.py is packaged as exe, and the libraries it USES are also evaluated in the d:/123 directory.
 
Second, run setup.py:
In the example provided with CXfreeze C:/ python31/lib /site-packages/cx_Freeze/samples/PyQt4, there is a setup.py file. Open this file and we find that it is:

By running this script, packaging can be done automatically:
For example, if you go into C:/ python31/lib /site-packages/cx_Freeze/samples/PyQt4,
run
setup.py build
After that, a build/exe.win32-3.1 directory will appear under this directory, where you can see the packaged exe file. We want to package our script, copy this setup.py over, and put it in
executables = [Executable(“PyQt4app.py”, base = base)])
Change pyqt4app.py to your own script name.
 
Problems during packaging:
For Chinese support, if there is Chinese in the script and the encoding format is not specified, the packaging process will occur: UnicodeDecodeError: ‘utf8’ codec can ‘t decode bytes in the position of 1602: invalid data this kind of mistake, this blog post on http://www.cnblogs.com/xinzaitian/archive/2010/12/10/1902481.html, the author mentioned Chinese must be deleted.
In fact, Chinese characters can be retained by adding the following at the beginning of the script file:
#! /usr/bin/env python
#coding=utf-8
It is ok
 
Another problem is that if the packaged EXE file is run under “desktop” or other Chinese path, a window will pop up showing “Cannot get zipimporter” instance. So far, no good solution has been found

The performance of these shells in Windows Vista

(1) Before the Server 2003 in good use of mole (Armadillo), EXE shell, running in the WIN98 environment, exit the program always report an error, but click “OK”, there is no other exception. So we keep putting shells in it.

in VISTA, however, it can only protect EXE files directly. If you want to create or edit a project, yes
! The “general extraction error: locate at ES1(
General Extraction Error location ES1) “. And it doesn’t matter what operating system the client is running in. So that it doesn’t work at all, it has to be done differently.

(2) asprotect_ske_2.3 0514 beta, serial number is required first after installation. The serial number generated with the crack file in its installation package is not recognized. So it can only be said that the installation is successful, the use of failure.

(3) Obsidium has reduced the EXE files I originally “occupy” a few megabytes to only a few hundred kilobytes, which is such a high compression rate that even the most professional compression software has to yield to it, right?You can imagine the consequences of the program running to pop”
stopped working
ends with a “message box.

(4) PELock’s case is similar to Obsidium’s.

(5) finally a success, due to my need to protect “own intellectual property”, I will not tell you. So that’s the end of the shell test.