Python error “ImportError: No module named”

后端 未结 29 2957
野的像风
野的像风 2020-11-22 07:46

Python is installed in a local directory.

My directory tree looks like this:

(local directory)/site-packages/toolkit/interface.py

29条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 08:11

    Yup. You need the directory to contain the __init__.py file, which is the file that initializes the package. Here, have a look at this.

    The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later.

提交回复
热议问题