Tag Archives: python

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

XLRDError: Excel xlsx file; Not supported error reporting solutions

The reason is that pip is installed with the latest version 2.0.1 and only supports. XLS files. So pandas.read_ Excel (‘xxx. Xlsx ‘) will report an error.

You can install the old version xlrd and execute the command in CMD:

pip uninstall xlrd
pip install xlrd==1.2.0

Solved the error report!

[Solved] sys.stderr.write(f“ERROR: {exc}“) ^ SyntaxError: invalid syntax

Reference link: (19 messages) two reasons and solutions for syntaxerror: invalid syntax in PIP instruction,

The relevant solutions in the original text are as follows:

However, the get-pip.py file was not found in the process of trying to solve it. Access the index of /.

https://bootstrap.pypa.io/ Observe that the relevant version of get-pip.py file is found in PIP

To sum up, the command to get-pip.py should be

wget https://bootstrap.pypa.io/pip/3.5/get-pip.py

After downloading, execute the following command
python3 get-pip.py

[Solved] Selenium Error: ERROR: Message: element not interactable

For this error, you can check whether there are duplicate elements on the next page

For example, the following: run the error on the old newspaper and find that there are duplicate elements on the page

password=(By.XPATH,'//input[@placeholder="Please input the password"])'

Solution: find the one you need, as follows

password=(By.XPATH,'(//input[@placeholder="Please input the password"])[2]')

Specify element positioning method: (//span [text() = ‘match’) [2]

Error = 2, no such file or director is prompted in the lower left corner of the MAC pycharm running file

Background:
System: MAC system
problem: Python runs the python project provided by others, but the file in the project exists, but it prompts that there is no such file
specific error:
error: cannot run program “/ users/Bob/pychamprojects/untitled/venv/bin/Python” (in directory “/ users/Bob/desktop/1”): error = 2, no such file or director

Solution:
delete the hidden. Idea file under the project, restart pycharm and run it again

Syntaxerror: unexpected EOF while parsing solution and ideas

Online learning code, error reporting

SyntaxError: unexpected EOF while parsing

If you encounter this problem, first check whether the parentheses are written less

View source code

res = sorted(res.iteritems(), key=lambda x : x[1])

The code is the version of python2. X. res.iteritems () has been dropped under python3. X, so it is modified to

res = sorted(res.items(), key=lambda x : x[1])

Solve the problem of error loading MySQL DB module. Encountered during Django project

Solve the problem of error loading MySQL DB module encountered during Django project

Python version 3.9 was used when creating the Django project. The MySQL database was successfully introduced in the process of doing the project, but later the python version was reduced to 3.7, so this error was reported when re running the system

Problem causes and solutions:
the package used by Django to connect to MySQL in Python 3 is pymysql, so the first step is to install pymysql:

pip install pymysql

Installation does not mean that it is OK. It also needs to be installed in the project__ init__. Add the following code to the. Py file:

import pymysql
pymysql.install_as_MySQLdb()


python multiprocessing.pool NameError: name is not defined

Question

The paper code encountered a problem similar to the following. After some efforts, it can be regarded as solving this problem.

# import torch
# # print(torch.__version__)
# # print(torch.cuda.is_available())
import multiprocessing
cores = multiprocessing.cpu_count() // 2
def b(xs):

    t = temp_num[xs[0]] * 2
    return t
def a():
    global temp_num
    temp_num = [4, 5, 6]
    pool = multiprocessing.Pool(cores)
    xs = range(3)
    batch_result = pool.map(b,xs)
    print(batch_result)
def main():
    a()
if __name__ == '__main__':
    main()

Error:

solve

import multiprocessing
cores = multiprocessing.cpu_count() // 2
def b(x):
    xs = x[0]
    temp_num = x[1]
    t = temp_num[xs] * 2
    return t
def a():
    global temp_num
    temp_num = [4, 5, 6]
    pool = multiprocessing.Pool(cores)
    xs = range(3)

    z =zip(xs,[temp_num] * 3)
    result = pool.map(b,z)
    print(result)
def main():
    a()

if __name__ == '__main__':

    main()

Import error, failed to import the debug version of PYD

Today, I used swig to encapsulate the underlying C + + library. After the result was encapsulated, release was OK. However, in the debug mode, the import failed all the time, indicating that the module could not be found. Why did I fail when I had PYD?

After troubleshooting, PYD in the original debug mode must be added_ d

The result is to add_ D is solved; For example_ Somelib.pyd should be_ someLib_ d. PYD, so Python can import.

Modify cmakelists.txt to ensure that it is added in debug mode_ d

set(CMAKE_DEBUG_POSTFIX _d)
set_target_properties(${target_name} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

Pyinstaller Error: [ImportError]: DLL load failed while importing _socket: Parameter error

Convert the python program to exe through pyinstaller and run normally on this computer, but an error is reported when running on other computers:
[importerror]: DLL load failed while importing_ Socket: parameter error
as shown in the following figure:

found many places without solutions

Finally, only the pyinstaller is reduced to 3.6, and the python version is also reduced to 3.6.8

Everything is normal after re-conversion!