![](/img/trans.png)
[英]python module installation error when deploying a Django application on heroku
[英]“npm: command not found” error when deploying Python application to Heroku
我剛剛創建了一個Heroku帳戶,並嘗試部署現有代碼。 當我嘗試git push heroku master
,出現以下錯誤:
Counting objects: 348, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (207/207), done.
Writing objects: 100% (348/348), 172.64 KiB | 0 bytes/s, done.
Total 348 (delta 138), reused 279 (delta 116)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: ! Warning: Multiple default buildpacks reported the
ability to handle this app. The first buildpack in the list below
will be used.
remote: Detected buildpacks: Python,Node.js
remote: See
https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-
order
remote: -----> Python app detected
remote: -----> Running pre-compile hook
remote: ----->Pre-compile hook
remote: -----> Running Webpack
remote: jquery-webpack-stats.json created
remote: webpack-stats.json created
remote: bin/run_webpack: line 15: npm: command not found
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to paytientdesktop.
remote:
To https://git.heroku.com/paytientdesktop.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to
'https://git.heroku.com/paytientdesktop.git'
這是我的app.json
文件:
{
"name": "myapp",
"description": "Myapp Heroku app.",
"scripts": {
"postdeploy": "python manage.py migrate"
},
"env": {
"ALLOWED_HOSTS": {
"description": "Django ALLOWED_HOSTS setting, e.g.:
.appname.herokuapp.com"
},
"DISABLE_COLLECTSTATIC": {
"description": "Heroku setting to disable Django collectstatic (it
is run by bin/post_compile)",
"value": "1"
},
"DJANGO_SETTINGS_MODULE": {
"description": "Django settings Python import path",
"value": "myapp.settings.production"
},
"SECRET_KEY": {
"description": "Django SECRET_KEY setting",
"generator": "secret"
}
},
"formation": {
"web": {
"quantity": 1,
"size": "free"
},
"worker": {
"quantity": 1,
"size": "free"
}
},
"addons": [
{
"plan": "heroku-postgresql:hobby-dev",
"options": {
"version": "9.5"
},
"as": "DATABASE"
},
{
"plan": "heroku-redis:hobby-dev",
"options": {
"version": "3.2"
},
"as": "REDIS"
},
{
"plan": "sendgrid:starter"
},
{
"plan": "papertrail:choklad"
},
{
"plan": "opbeat:free"
}
],
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "heroku/python"
}
]
}
我該如何解決?
Heroku使用buildpack構建應用程序,每個buildpack都特定於特定的編程語言和工具集。
在許多情況下,Heroku可以通過在存儲庫中查找某些指標文件來檢測應使用的buildpack。 例如,如果存儲庫的根目錄中包含requirements.txt
文件或Pipfile
和Pipfile.lock
文件,則將調用正式的Python buildpack 。
上面的失敗部署的輸出包含以下信息:
remote: ! Warning: Multiple default buildpacks reported the
ability to handle this app. The first buildpack in the list below
will be used.
remote: Detected buildpacks: Python,Node.js
remote: See
https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-
order
Heroku在默認情況下僅運行一個buildpack,並且不知道應為應用程序使用Python的buildpack還是Node.js的buildpack。 它正在選擇Python。
好消息是您可以在一個應用程序中使用多個buildpack 。 您只需要做一些手動工作即可告訴Heroku應該使用哪個buildpack,以及使用什么順序 。
這是一個適合您的示例:
首先,設置您的一個構建包。 我喜歡使用這里的主要語言。
heroku buildpacks:set heroku/python
接下來,以正確的順序添加其他buildpack,由--index
參數控制。 看起來您的Python構建依賴於npm
,因此您需要在Python構建包之前運行Node.js構建包。
heroku buildpacks:add --index 1 heroku/nodejs
通過運行heroku buildpacks
確認您的buildpacks正確配置。 您應該首先看到Node.js構建包,然后是Python構建包。
再次將您的代碼推送到Heroku並觀看其編譯!
app.json
無法app.json
工作? 您的app.json
文件列出了Node.js和Python構建包。 為什么不起作用?
我從未使用過app.json
,並且已經使用Heroku大約五六年了。 在Heroku上運行應用程序當然不是必需的。
看起來app.json
專門用於Heroku的Platform API,它將用於啟動一個全新的應用程序(與將代碼部署到已定義的應用程序相反)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.