问题描述
我正在尝试为我的 Python 应用程序实现 Deploy to Heroku 功能:https://github.com/jet-admin/jet-bridge/tree/heroku
I'm trying to implement Deploy to Heroku functionality for my Python application:https://github.com/jet-admin/jet-bridge/tree/heroku
如果只使用 requirements.txt 来安装依赖项也可以,但它需要我修改我的 requirements.txt 以包含一些我通常不需要的额外包(psycopg2、mysqlclient).
It woks OK if just use requirements.txt to install dependencies, but it require me to modify my requirements.txt to include some extra packages that i normally don't need (psycopg2, mysqlclient).
是否可以不将所有要求都包含在 requirements.txt 中,而是使用一些额外的命令进行安装?我已经尝试添加将执行 pip install 命令的 postdeploy 脚本,但是在部署成功后我的应用程序说没有安装 psycopg2(我以为我在 postdeploy 命令中安装了它).
Is it possible not to include all requirements in requirements.txt, but install it with some extra command? I've tried adding postdeploy script which will perform pip install command, but after deploy succed my application says that psycopg2 is not installed (thought i installed it in postdeploy command).
推荐答案
Heroku Python buildpack 有 一个钩子,你可以在其中执行额外的命令在初始 slug 编译之后.
要使用它,您可以添加一个 bin/post_compile
文件,将安装额外包的 shell 命令放入其中.
To use it, you can add a bin/post_compile
file, putting inside the shell commands for installing the extra packages.
你甚至可以让它依赖于一个环境变量,比如:
You can even make it depend on an environment variable, like:
# assuming you have files mysql-requirements.txt and postgres-requirements.txt
if [ "$JET_BRIDGE_DB" == "mysql" ]; then
echo "Installing Python dependencies for MySQL support"
pip install -r mysql-requirements.txt
else
echo "Assuming Postgres database, installing Python dependencies"
pip install -r postgres-requirements.txt
fi
阅读更多:
- Buildpacks:https://devcenter.heroku.com/articles/buildpacks立>
- Heroku Python Buildpack:https://github.com/heroku/heroku-buildpack-python
- Slug 编译:https://devcenter.heroku.com/articles/slug-compiler
这篇关于使用额外的 pip install 将 Python 应用程序部署到 Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!