(1) reason
because PyCharm Start the interpreter (Interpreter) When It will not only be imported into environment variables sys.path Discovered modules , It will also import modules under the current working directory . When you are in IDLE When starting the interpreter in , The current working directory is the project directory , Can smoothly call modules in the same project ;
But when you When starting from the command line , The current working directory is the directory where you started the interpreter ( namely python Installation directory ), If the location is not the project directory , Then the modules in the project directory will not be found .
(2) solve
Add :
import sys
sys.path.append(" Project absolute path ") # Ensure that when the terminal is running , Can be retrieved to the directory