Python3.6.4 import file reporting module does not exist

such a simple folder with c7 and c8 files in the same folder.
clipboard.png


c7

clipboard.png

clipboard.png

clipboard.png

I think it"s the environment, but you can"t find it. Other normal runs are good

Apr.11,2021
For

PyCharm , you can see this How do I import modules in pycharm?


.

there are two solutions

  1. set the python running directory to the same directory as c7.py ( C:\ Users\ Administrator\ Desktop\ py\ ).
  2. add the directory where c7.py is located to the PYTHONPATH environment variable.

seems to have encountered this problem before, and then I had to add sys.path.append


at the beginning. For the problem of

relative path, you can set it this way. It can be used in both pycharm and cmd

.
import os
import sys

project_path = os.path.abspath(os.path.join('.'))
sys.path.append(project_path)
Menu