侧边栏壁纸
博主头像
996worker

祇園精舎の鐘の聲, 諸行無常の響き有り。

  • 累计撰写 189 篇文章
  • 累计创建 46 个标签
  • 累计收到 8 条评论

目 录CONTENT

文章目录

Can not find python modules while running python project in console

996worker
2022-04-29 / 0 评论 / 0 点赞 / 84 阅读 / 439 字
温馨提示:
本文最后更新于 2022-04-29,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

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.

0

评论区