Python error “ImportError: No module named”

后端 未结 29 2690
野的像风
野的像风 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 07:51

    1. You must have the file __ init__.py in the same directory where it's the file that you are importing.
    2. You can not try to import a file that has the same name and be a file from 2 folders configured on the PYTHONPATH.

    eg: /etc/environment

    PYTHONPATH=$PYTHONPATH:/opt/folder1:/opt/folder2

    /opt/folder1/foo

    /opt/folder2/foo

    And, if you are trying to import foo file, python will not know which one you want.

    from foo import ... >>> importerror: no module named foo

提交回复
热议问题