python - 在 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?```
解决方案
推荐阅读
- c# - 如何使用特定的关键条件实体框架核心 3.1 检查(从日期 + 时间 - 到日期 + 时间)
- spring-boot - Spring批处理 - 如何将自己的值写入输出文件中的标题
- powerbuilder - 如何以编程方式在 Powerbuilder 中单击 F5
- angular - 有什么作用?在 Angular 函数参数中是什么意思?
- realm - 我想将我的数据存储在 Android Studio 的 Realm 数据库中,但它不工作
- php - GROUP BY id 仅在我的 MySQL 查询中有效
- c# - 在 C# 中进行唤醒词语音识别的最佳方法是什么
- delphi - 多端口上的delphi tcp服务器在关闭时挂起
- conan - 获取柯南包的配方(conanfile.py)?
- php - 如何加入已被另一个表加入的表