Python error “ImportError: No module named”

后端 未结 29 2683
野的像风
野的像风 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:00

    You are reading this answer says that your __init__.py is in the right place, you have installed all the dependencies and you are still getting the ImportError.

    I was facing a similar issue except that my program would run fine when ran using PyCharm but the above error when I would run it from the terminal. After digging further, I found out that PYTHONPATH didn't have the entry for the project directory. So, I set PYTHONPATH per Import statement works on PyCharm but not from terminal:

    export PYTHONPATH=$PYTHONPATH:`pwd`  (OR your project root directory)
    

    There's another way to do this using sys.path as:

    import sys
    sys.path.insert(0,'') OR
    sys.path.append('')
    

    You can use insert/append based on the order in which you want your project to be searched.

提交回复
热议问题