Python import Error: No module named src


Generally appear in use pycharm write python, using the from src.util situation to import function and is deployed on the server or sublime run.

Run from the command line

When running, it should be run in the srcsame level directory
[ run in the root directory of the project]

Modify the code

Add the following to the head of the running file

import os
import sys
cur_path=os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, cur_path+"/..")

It can be solved.

Guess you like

Origin blog.csdn.net/qq_32507417/article/details/107858768