Python Learning importerror Error

Source: Internet
Author: User

The main share of this article is Pythonof theImporterrorErrorRelated content, come together to look at it, hope to learn Python to help you. problemError:Importerror:no module named XXXin thePythonIn a project, you occasionally encounter cases where files cannot be referenced, i.e.pycharm IDEfile jumps are supported, but the module cannot be found when the file is executed. For example, the error is as follows: Traceback (most recentPager Last): File"Utils/average_clinic.py", line 17,inch<Module> fromUtils.file_utilsImportListdir_files, show_string Importerror:NoModuleNamed File_utils SolveFirst, inPyAt the top of the file, introduce the root directory, such as Import OS Import Sys p = os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))ifP notinchSys.path: Sys.path.append (P) # Print P #Show PathSecond, check the file'sWorking directory, Location:
The first step is to import the project path, and the second step is to check the working directory of the file. First check the working directory, followed by the project path. Also, be aware thatPycharmautomatically generated file references are not necessarily correct, such as: fromFile_utilsImportListdir_files, show_string#wrong reference, file is in the same directory, no package name is used# from Utils.file_utils import listdir_files, show_stringSource:Csdn

Python Learning importerror Error

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.