996Worker
996Worker
发布于 2022-04-29 / 194 阅读
0
0

Can not find python modules while running python project in console

Problem

I can run my python project in PyCharm, but if I try to run the project with console, like python app.py, I got "modules not found" errors.

I can ensure that all dependencies are installed via pip install -r requirements.txt.

Solution

Add code snippts below at the start of the entrance app.py file of the project.

import sys
import os

curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)

Then I can run the python project in console.


评论