Python script reports AttributeError: 'module' object has no attribute 'xxx' solution,

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.