首页 > 解决方案 > 在 docker 文件中将环境变量添加到 PYTHONPATH

问题描述

我正在尝试对使用一些自定义模块的 Django 应用程序进行 docker 化,为了导入它们,我需要将它们的路径添加到 PYTHONPATH 问题是当我尝试这样做时,我覆盖了 PYTHONPATH,因此它不再检测到 Django。

我试过的命令:

ENV PYTHONPATH "${PYTONPATH}:/mypath"

ENV PYTHONPATH "$PYTONPATH:/mypath"

RUN export PYTHONPATH="$PYTHONPATH:/mypath" 

我还尝试创建一个 .bash_profile 文件,添加了路径并运行 source .bash_profile 但没有成功:

CMD echo "export PYTHONPATH='/mypath'" > ./.bash_profile

CMD source ./.bash_profile

错误信息:

Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?```

标签: pythondjangodockerdockerfilepythonpath

解决方案


推荐阅读