Python script reports AttributeError: 'module' object has no attribute 'xxx' solution,
The Python script is completely normal, but the error "AttributeError: 'module' object has no attribute 'xxx'" is reported during execution '". This is actually a problem with the. pyc file.
Problem locating:
Check the source file of the import database and find that the source file exists and there is no error, and the. pyc file of the source file also exists.
Solution:
1. Do not name the py script with the same reserved characters or module name as python.
2. delete. pyc file (because the py script is generated every time it is run. pyc file; In the generated. if the code is not updated in the pyc file, pyc is still used during runtime, so you need to delete it. pyc file), re-run the Code; or find an environment that can run the code, copy and replace the current machine. pyc file.
Appendix:
Pyc file Introduction
The pyc file is a bytecode file compiled by python. As long as you run the py file, the python compiler will automatically generate a corresponding pyc bytecode file. This pyc bytecode file is generated by the python interpreter to run the machine code (this is also why the pyc file can be deployed across platforms, similar to the java cross-platform, java JVM running bytecode file ). The next call directly calls pyc without calling the py file. Until your py file has changed. The python interpreter checks the generation time in the pyc file and compares the modification time of The py file. If py is updated, a new pyc is generated.