Python database operation method, device and equipment based on PyInstaller and medium

By packaging the database connection driver and Python source code in PyInstaller, the problem of incomplete packaging of database drivers in the existing technology is solved, which improves the portability and user experience of test scripts, and reduces the difficulty of writing.

CN119938138APending Publication Date: 2025-05-06HANGZHOU HONGSHU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510073753.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-17
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

When handling database libraries, the existing technology cannot effectively package the drivers they depend on, resulting in poor portability of test scripts and increasing the difficulty of script writing.

Method used

Download the corresponding connection driver through the preset database connection component, and use PyInstaller to package the connection driver and Python source code into an executable program, which is directly executed in the target environment.

Benefits of technology

It improves the portability of test scripts and the convenience of user use, reduces the writing technical requirements, and enables the operation of different databases to be uniformly carried out through the Python DB-API v2.0 interface specification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938138A_ABST
    Figure CN119938138A_ABST
Patent Text Reader

Abstract

The invention discloses a Python database operation method and device based on a PyInstaller, equipment and a medium, and relates to the technical field of computers. Comprising the steps of downloading a corresponding connection drive program for a to-be-operated database through a preset database connection component; acquiring database connection parameters, and establishing database connection between the connection driving program and the to-be-operated database based on the database connection parameters; the database connection parameters comprise path data of a connection driving program, a program class name of the connection driving program, address data of a to-be-operated database and identity data of the to-be-operated database; and generating a target executable program based on the connection driving program and the Python source code by utilizing the PyInstaller, and executing a preset operation instruction on the to-be-operated database by utilizing the database connection through the target executable program. Therefore, the portability of the test script program and the use convenience of the user can be improved, and the writing technical requirements are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a Python database operation method, device, equipment and medium based on PyInstaller. Background Art

[0002] Python is widely used by software testers in writing automated test scripts because of its simplicity, ease of learning and powerful functions. Among them, operating the database is a common requirement in automated test scripts, that is, Python uses third-party libraries to implement database connection and addition, deletion, modification and query operations, such as the cx_oracle library for operating Oracle databases and the PyMySQL library for operating Mysql databases. After the test script is written, a common scenario is to deliver it to other testers or deploy it to the environment where the application under test is located to perform the test. The test script includes source code files, third-party dependency libraries and resource files. In order to facilitate the use of the target delivery personnel and confidentiality requirements, the test script needs to be packaged into an executable package using the PyInstaller tool for delivery, so that the target personnel do not need to deal with dependency packages and access source code, and can directly execute the program.

[0003] Although PyInstaller can package Python source code files and dependent libraries, when dealing with database operation libraries such as cx_oracle, it does not package the Oracle Instant Client (a set of lightweight network connection and data feature libraries) that the cx_oracle library depends on. It still needs to be installed separately in the execution environment, resulting in poor portability of the script. In addition, for different databases, Python needs to install specific third-party libraries, which increases the difficulty of script writing.

[0004] From the above, it can be seen that how to increase the portability of test script programs and the convenience of user use and reduce the writing technical requirements is an urgent problem to be solved. Summary of the invention

[0005] In view of this, the purpose of the present invention is to provide a Python database operation method, device, equipment and medium based on PyInstaller, which can increase the portability of test script programs and the convenience of user use, and reduce the technical requirements for writing. The specific scheme is as follows:

[0006] In a first aspect, the present application provides a Python database operation method based on PyInstaller, comprising:

[0007] Download the corresponding connection driver for the database to be operated through the preset database connection component;

[0008] Acquire database connection parameters, and establish a database connection between the connection driver and the database to be operated based on the database connection parameters; the database connection parameters include path data of the connection driver, program class name of the connection driver, address data of the database to be operated, and identity data of the database to be operated;

[0009] A target executable program is generated based on the connection driver and Python source code using PyInstaller, and preset operation instructions are executed on the database to be operated using the database connection through the target executable program.

[0010] Optionally, the preset database connection component is a JayDeBeApi component, and the connection driver is a JDBC driver;

[0011] The database connection parameters include first parameter information of the JDBC driver and second parameter information of the database to be operated.

[0012] Optionally, before downloading a corresponding connection driver for the database to be operated by using a preset database connection component, the method further includes:

[0013] Install the JayDeBeApi component through Python's built-in package management program pip.

[0014] Optionally, executing a preset operation instruction on the database to be operated by using the database connection through the target executable program includes:

[0015] The target executable program utilizes the database connection to execute preset operation instructions that comply with API specifications on the database to be operated.

[0016] Optionally, establishing a database connection between the connection driver and the database to be operated based on the database connection parameters includes:

[0017] Using the database connection parameters as parameters of a preset database connection function;

[0018] The connection driver is connected to the database to be operated by calling the preset database connection function.

[0019] Optionally, the generating a target executable program based on the connection driver and Python source code using PyInstaller includes:

[0020] The Python source code and the target execution parameters are packaged to obtain a corresponding package file; the target execution parameters are added with a resource file determined based on the directory where the connection driver is located;

[0021] Updating the parameters of the preset database connection function;

[0022] The target executable program is generated using PyInstaller based on the packaged file and the updated parameters of the preset database connection function.

[0023] Optionally, the updating operation on the parameters of the preset database connection function includes:

[0024] The parameters of the preset database connection function are updated by adding preset attributes to the path information of the connection driver.

[0025] In a second aspect, the present application provides a Python database operation device, comprising:

[0026] A connection driver acquisition module is used to download a corresponding connection driver for a database to be operated through a preset database connection component;

[0027] A database connection establishment module, used to obtain database connection parameters, and establish a database connection between the connection driver and the database to be operated based on the database connection parameters; the database connection parameters include path data of the connection driver, program class name of the connection driver, address data of the database to be operated, and identity data of the database to be operated;

[0028] The target executable program generation module is used to generate a target executable program based on the connection driver and Python source code using PyInstaller, and execute preset operation instructions on the database to be operated using the database connection through the target executable program.

[0029] In a third aspect, the present application provides an electronic device, including:

[0030] Memory, used to store computer programs;

[0031] The processor is used to execute the computer program to implement the aforementioned Python database operation method based on PyInstaller.

[0032] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned PyInstaller-based Python database operation method.

[0033] The present application provides a Python database operation method based on PyInstaller. First, a corresponding connection driver program is downloaded for a database to be operated through a preset database connection component; then database connection parameters are obtained, and a database connection is established between the connection driver program and the database to be operated based on the database connection parameters; the database connection parameters include path data of the connection driver program, a program class name of the connection driver program, address data of the database to be operated, and identity data of the database to be operated; finally, PyInstaller is used to generate a target executable program based on the connection driver program and Python source code, and the database connection is used by the target executable program to execute preset operation instructions on the database to be operated.

[0034] As can be seen from the above, the present application establishes a database connection between the connection driver and the database to be operated, and uses the database connection to execute preset operation instructions on the database to be operated through the target executable program. That is, when processing the operation database, the data in the database to be operated can be directly called by establishing a database connection, and there is no need to install the database to be operated in the execution environment. Therefore, the portability of the test script program and the convenience of user use can be increased, and the technical requirements for writing can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0036] Figure 1 A flowchart of a Python database operation method based on PyInstaller disclosed in this application;

[0037] Figure 2 A flowchart of a specific Python database operation method based on PyInstaller disclosed in this application;

[0038] Figure 3 A flow chart of the JayDeBeApi packaging method based on PyInstaller disclosed in this application;

[0039] Figure 4 A schematic diagram of a Python database operation device based on PyInstaller disclosed in this application;

[0040] Figure 5 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0041] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0042] After the test script is written, a common situation is to deliver it to other testers or deploy it to the environment where the tested application is located to perform the test. The test script includes source code files, third-party dependency libraries, and resource files. In order to facilitate the use of the target delivery personnel and confidentiality requirements, the test script needs to be packaged into an executable package using the PyInstaller tool for delivery, so that the target personnel do not need to deal with dependency packages and contact source code, and can directly execute the program. Although PyInstaller can realize the packaging of Python source code files and dependency libraries, when processing libraries such as cx_oracle that operate databases, it will not package the Oracle Instant Client (a set of lightweight network connections and data feature libraries) on which the cx_oracle library depends, and it still needs to be installed separately in the execution environment, resulting in poor portability of the script. And for different databases, Python needs to install specific third-party libraries, which increases the difficulty of script writing. Therefore, the present application discloses a Python database operation scheme based on PyInstaller, which can increase the portability of the test script program and the convenience of user use, and reduce the technical requirements for writing.

[0043] See also Figure 1 As shown, the embodiment of the present application discloses a Python database operation method based on PyInstaller, including:

[0044] Step S11: downloading a corresponding connection driver program for the database to be operated through a preset database connection component.

[0045] In this embodiment, the corresponding connection driver program is downloaded for the database to be operated through the preset database connection component. The preset database connection component is the JayDeBeApi component, and the connection driver program is the JDBC driver program; the type of the database to be operated is any type of database in the Python database, which is not specifically limited here. For example, in a specific implementation, the database to be operated is an Oracle database. Accordingly, the downloading of the corresponding connection driver program for the database to be operated through the preset database connection component may include: downloading ojdbc.jar (the JDBC driver program corresponding to the Oracle database) for the Oracle database through the JayDeBeApi component.

[0046] It should be noted that before downloading the corresponding connection driver for the database to be operated through the preset database connection component, the preset database connection component needs to be installed in the system. Specifically, before downloading the corresponding connection driver for the database to be operated through the preset database connection component, it can also include: installing the JayDeBeApi component through the package management program pip that comes with Python.

[0047] Step S12: Obtain database connection parameters, and establish a database connection between the connection driver and the database to be operated based on the database connection parameters.

[0048] In this embodiment, the database connection parameters include the first parameter information of the JDBC driver and the second parameter information of the database to be operated. Specifically, the database connection parameters include the path data of the connection driver, the program class name of the connection driver, the address data of the database to be operated, and the identity data of the database to be operated. For example, in a specific implementation, the database connection parameters include the JDBC driver path, the connection string, the user name and the password.

[0049] Furthermore, a database connection is established between the connection driver and the database to be operated based on the database connection parameters. Specifically, the database connection is established between the connection driver and the database to be operated based on the database connection parameters, which may include: using the database connection parameters as parameters of a preset database connection function; establishing a database connection between the connection driver and the database to be operated by calling the preset database connection function. The parameters of the preset database connection function include the JDBC driver class name, the actual address of the database to be connected, the actual account of the database to be connected, and the JDBC driver path; the JDBC driver class name needs to be determined according to the actual application situation. For example, in a specific implementation, for an Oracle database, the corresponding class name of the JDBC driver is oracle.jdbc.driver.OracleDriver.

[0050] Step S13: using PyInstaller to generate a target executable program based on the connection driver and the Python source code, and using the target executable program to use the database connection to execute preset operation instructions on the database to be operated.

[0051] In this embodiment, PyInstaller is used to package the connection driver and Python source code to generate a target executable program. Specifically, the use of PyInstaller to generate a target executable program based on the connection driver and Python source code may include: packaging the Python source code and target execution parameters to obtain a corresponding packaged file; adding a resource file determined based on the directory where the connection driver is located to the target execution parameters; updating the parameters of the preset database connection function by adding preset attributes to the path information of the connection driver; and using PyInstaller to generate the target executable program based on the packaged file and the updated parameters of the preset database connection function. That is, by encapsulating JayDeBeApi in PyInstaller, the Python script can directly use JDBC to connect and operate the database without using additional third-party libraries for different databases, and the Oracle InstantClient required by the cx_oracle library, for example, does not need to be installed separately, which increases the portability of the delivery program and the convenience of user use.

[0052] It is worth mentioning that the target executable program utilizes the database connection to execute preset operation instructions that comply with the API specification on the database to be operated. For example, in a specific implementation, a specific SQL statement is executed, including but not limited to creating a cursor, executing an SQL query, and obtaining query results. The above method for operating a database complies with the Python DB-API v2.0 specification and is applicable to other databases besides the above-mentioned Oracle database. In other words, a unified Python DB-API v2.0 interface specification can be used for interaction with various databases, reducing the technical requirements for writing and the learning cost of personnel.

[0053] As can be seen from the above, the embodiment of the present application establishes a database connection between the connection driver and the database to be operated, and uses the database connection to execute preset operation instructions on the database to be operated through the target executable program. That is, when processing the operation database, the data in the database to be operated can be directly called by establishing a database connection, and there is no need to additionally install the database to be operated in the execution environment. At the same time, for script writers, a unified interface specification can be used for interaction with various databases, reducing the technical requirements for writing and the learning cost of personnel. Thereby, the portability of the test script program and the convenience of user use can be increased, and the technical requirements for writing can be reduced.

[0054] See also Figure 2 As shown, the embodiment of the present application discloses a specific Python database operation method based on PyInstaller, including:

[0055] In this embodiment, JayDeBeApi is installed using Python's own package manager pip, and the corresponding JDBC driver is downloaded for the target database to be operated; database connection parameters are prepared, and a database connection is established based on the database connection parameters. The database connection parameters include the JDBC driver path, connection string, user name and password. In a specific implementation, for an Oracle database, the specific examples are as follows:

[0056] jdbc_driver = ' / path / to / jdbc / ojdbc.jar';

[0057] connection_url = 'jdbc:oracle:thin:@localhost:1521:mydatabase';

[0058] username = 'myusername';

[0059] password = 'mypassword';

[0060] conn = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver', connection_url, [username, password], [jdbc_driver]).

[0061] It should be noted that the first parameter of the connect method above represents the JDBC driver class name. The class name in the example is suitable for Oracle database, and other databases should set the corresponding class name; the second parameter is configured according to the actual address of the database to be connected; the third parameter is configured according to the actual database account, and the data type is a list of user name and password; the fourth parameter is the JDBC driver path downloaded in step 2 above, and is passed in as a list.

[0062] In this embodiment, specific SQL statements are executed, including but not limited to creating a cursor: cursor = conn.cursor(), executing SQL queries: cursor.execute("select * from mytable"), and obtaining query results: results = cursor.fetchall(). The above method for operating a database complies with the Python DB-API v2.0 specification and is applicable to other databases except the Oracle database in the example.

[0063] See also Figure 3 As shown, in this embodiment, in addition to conventionally packaging the Python source code, PyInstaller needs to add the directory where the JDBC driver is located as a resource file to the execution parameters for packaging together. The specific parameters are as follows: pyinstaller --add-data " / path / to / jdbc:jdbc". Further, modify the assignment of the JDBC driver file path variable in the script. When the script is executed in the PyInstaller encapsulation environment, the '_MEIPASS' attribute will be automatically added to Python's sys built-in library to represent the actual storage path of the encapsulated resource file. Specifically, the jdbc_driver variable value is modified to: os.path.join(getattr(sys, '_MEIPASS'), 'jdbc', 'ojdbc.jar'), and then the PyInstaller encapsulation process can be executed normally.

[0064] As can be seen from the above, the embodiment of the present application provides a database operation method based on JayDeBeApi and an encapsulation method in PyInstaller. Python scripts can directly use JDBC to connect and operate the database without using additional third-party libraries for different databases. For example, the Oracle Instant Client dependency required by the cx_oracle library does not need to be installed separately, which increases the portability of the delivery program and the convenience of user use. At the same time, for script writers, a unified Python DB-API v2.0 interface specification can be used for interaction with various databases, reducing the technical requirements for writing and the learning cost of personnel. Thereby, the portability of the test script program and the convenience of user use can be increased, and the technical requirements for writing can be reduced.

[0065] Accordingly, see Figure 4 As shown, the embodiment of the present application discloses a Python database operation device based on PyInstaller, including:

[0066] A connection driver acquisition module 11 is used to download a corresponding connection driver for a database to be operated through a preset database connection component;

[0067] A database connection establishment module 12 is used to obtain database connection parameters and establish a database connection between the connection driver and the database to be operated based on the database connection parameters; the database connection parameters include path data of the connection driver, program class name of the connection driver, address data of the database to be operated, and identity data of the database to be operated;

[0068] The target executable program generating module 13 is used to generate a target executable program based on the connection driver and Python source code using PyInstaller, and execute preset operation instructions on the database to be operated using the database connection through the target executable program.

[0069] As can be seen from the above, the embodiment of the present application establishes a database connection between the connection driver and the database to be operated, and uses the database connection to execute preset operation instructions on the database to be operated through the target executable program. That is, when processing the operation database, the data in the database to be operated can be directly called by establishing a database connection, and the database to be operated does not need to be additionally installed in the execution environment. Therefore, the portability of the test script program and the convenience of user use can be increased, and the technical requirements for writing can be reduced.

[0070] In some specific implementations, the preset database connection component is a JayDeBeApi component, and the connection driver is a JDBC driver;

[0071] The database connection parameters include first parameter information of the JDBC driver and second parameter information of the database to be operated.

[0072] Correspondingly, the Python database operation device based on PyInstaller may further include:

[0073] The JayDeBeApi component installation module is used to install the JayDeBeApi component through the package management program pip that comes with Python.

[0074] In some specific implementations, the database connection establishment module 12 may specifically include:

[0075] A database connection function determination unit, configured to use the database connection parameters as parameters of a preset database connection function;

[0076] The database connection establishing unit is used to establish a database connection between the connection driver and the database to be operated by calling the preset database connection function.

[0077] In some specific implementations, the target executable program generation module 13 may specifically include:

[0078] A target execution parameter packaging unit is used to package the Python source code and the target execution parameter to obtain a corresponding package file; the target execution parameter is added with a resource file determined based on the directory where the connection driver is located;

[0079] A database connection function update submodule, used to update the parameters of the preset database connection function;

[0080] A target executable program generating unit, configured to generate the target executable program based on the packaged file and the updated parameters of the preset database connection function by using PyInstaller;

[0081] The preset operation instruction execution unit is used to execute the preset operation instruction that complies with the API specification on the database to be operated by using the database connection through the target executable program.

[0082] Furthermore, in some specific implementations, the database connection function update submodule may specifically include:

[0083] The preset attribute adding unit is used to update the parameters of the preset database connection function by adding preset attributes to the path information of the connection driver.

[0084] Furthermore, the present application also discloses an electronic device. Figure 5 It is a structural diagram of an electronic device 20 shown according to an exemplary embodiment, and the content in the figure cannot be regarded as any limitation on the scope of use of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input and output interface 25 and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the Python database operation method based on PyInstaller disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment can specifically be an electronic computer.

[0085] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0086] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0087] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the Python database operation method based on PyInstaller executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0088] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed Python database operation method based on PyInstaller is implemented. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiments, and will not be repeated here.

[0089] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0090] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0091] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0092] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0093] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A Python database operation method based on PyInstaller, characterized in that: include: Download the corresponding connection driver for the database to be operated through the preset database connection component; Acquire database connection parameters, and establish a database connection between the connection driver and the database to be operated based on the database connection parameters; the database connection parameters include path data of the connection driver, program class name of the connection driver, address data of the database to be operated, and identity data of the database to be operated; A target executable program is generated based on the connection driver and Python source code using PyInstaller, and preset operation instructions are executed on the database to be operated using the database connection through the target executable program.

2. The Python database operation method based on PyInstaller according to claim 1, characterized in that: The preset database connection component is the JayDeBeApi component, and the connection driver is the JDBC driver; The database connection parameters include first parameter information of the JDBC driver and second parameter information of the database to be operated.

3. The Python database operation method based on PyInstaller according to claim 2, characterized in that: Before downloading the corresponding connection driver for the database to be operated by the preset database connection component, the method further includes: Install the JayDeBeApi component through Python's built-in package management program pip.

4. The Python database operation method based on PyInstaller according to claim 1, characterized in that: The step of executing a preset operation instruction on the database to be operated by using the database connection through the target executable program includes: The target executable program utilizes the database connection to execute preset operation instructions that comply with API specifications on the database to be operated.

5. The Python database operation method based on PyInstaller according to any one of claims 1 to 4, characterized in that: The step of establishing a database connection between the connection driver and the database to be operated based on the database connection parameters includes: Using the database connection parameters as parameters of a preset database connection function; The connection driver is connected to the database to be operated by calling the preset database connection function.

6. The Python database operation method based on PyInstaller according to claim 5, characterized in that: The method of using PyInstaller to generate a target executable program based on the connection driver and Python source code includes: The Python source code and the target execution parameters are packaged to obtain a corresponding package file; the target execution parameters are added with a resource file determined based on the directory where the connection driver is located; Updating the parameters of the preset database connection function; The target executable program is generated using PyInstaller based on the packaged file and the updated parameters of the preset database connection function.

7. The Python database operation method based on PyInstaller according to claim 6, characterized in that: The updating operation on the parameters of the preset database connection function includes: The parameters of the preset database connection function are updated by adding preset attributes to the path information of the connection driver.

8. A Python database operation device, characterized in that: include: A connection driver acquisition module is used to download a corresponding connection driver for a database to be operated through a preset database connection component; A database connection establishment module, used to obtain database connection parameters, and establish a database connection between the connection driver and the database to be operated based on the database connection parameters; the database connection parameters include path data of the connection driver, program class name of the connection driver, address data of the database to be operated, and identity data of the database to be operated; The target executable program generation module is used to generate a target executable program based on the connection driver and Python source code using PyInstaller, and execute preset operation instructions on the database to be operated using the database connection through the target executable program.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the Python database operation method based on PyInstaller as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the Python database operation method based on PyInstaller as described in any one of claims 1 to 7 is implemented.