Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The problem of module error reporting under different paths imported under PyCharm-- project

Shulou Source: shulou.com Published: 2022-06-03 05:13:03 09月18日 Update

When using PyCharm, we often encounter py scripts written by import itself, which prompt that the module is not located, resulting in import failure.

Let's look at an example:

Directory structure:

-the code actually written

-Interface

-* * _ check.py

Test_***_all_copy.py

We need to import the sibling directory under the folder interface in the test_***_all_copy.py script.

* * _ check.py all the classes and functions contained in the py file.

The following words are incorrect:

If you directly import all the files under * * _ check, an error will be reported.

All the py files in this import folder, which is written incorrectly, will prompt that the relevant class or function cannot be found under * _ check.

This kind of writing directly to the top-level directory of project is sometimes successful. But I failed this time, so you can use it according to the situation.

The following import method is correct, which is directly followed by the py file * check from the interface of the same level directory.

Import all under Interface.***_check.

Tags: Files directories functions siblings folders scripts prompts modules success code examples writing actual situation methods to make structure error top level will report Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi Shulou Information MariaDB MySQL