Heroku上的Python和Node.js.

Hay*_*ych 2 python heroku node.js

我已经开始创建一个在Heroku上运行的Node服务器.它工作正常,直到我尝试使用(非官方)Duolingo API.我编写了以下Python脚本来连接到API:

import duolingo
import simplejson as json

lingo  = duolingo.Duolingo('harleyrowland')
print json.dumps(lingo.get_user_info())
Run Code Online (Sandbox Code Playgroud)

我的节点服务器使用以下命令使用它:

var python = require('python-shell');

module.exports = {
  getData: function(callback){
    python.run('duoScript.py', function (err, results) { 
      console.log(err);
      console.log(results);
      var res = JSON.parse(results);
      var language = res.language_data.es.language_string;
      var streak = res.language_data.es.streak;
      var level = res.language_data.es.level;
      var levelPerecentage = res.language_data.es.level_percent;
      var fluency = res.language_data.es.fluency_score;
      var nextLesson = res.language_data.es.next_lesson.skill_title;
      return callback({language, streak, level, levelPerecentage, fluency, nextLesson});
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

这一切都在当地完全没问题.

当我把它推到Heroku时,代码不起作用,我开始在Heroku日志中得到以下错误:

{ [Error: ImportError: No module named duolingo]
     2016-10-06T00:02:32.133315+00:00 app[web.1]:   traceback: 'Traceback (most recent call last):\n  File "duoScript.py", line 1, in <module>\n    import duolingo\nImportError: No module named duolingo\n',
    executable: 'python',
    options: null,
    script: 'duoScript.py',
    args: null,
    exitCode: 1 
}
Run Code Online (Sandbox Code Playgroud)

因此,我继续使用Heroku API,发现我需要添加一个requirements.txt文件.所以我做了:

duolingo-api==0.3
simplejson==3.8.2
Run Code Online (Sandbox Code Playgroud)

哪些仍然无效.然后我找到了这个答案并添加了一个.buildpacks文件:

https://github.com/heroku/heroku-buildpack-python.git
https://github.com/heroku/heroku-buildpack-nodejs.git
Run Code Online (Sandbox Code Playgroud)

我仍然得到同样的错误.

知道是什么导致了这个错误吗?

更新1

以为我会显示我的Procfile,这就是问题所在:

web: node index.js
pipinstall: pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)

更新2

输出git push heroku masterpipinstall:

$ git push heroku master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote: 
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote: 
remote: -----> Installing binaries
remote:        engines.node (package.json):  5.9.1
remote:        engines.npm (package.json):   unspecified (use default)
remote:        
remote:        Downloading and installing node 5.9.1...
remote:        Using default npm version: 3.7.3
remote: 
remote: -----> Restoring cache
remote:        Loading 2 from cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (not cached - skipping)
remote: 
remote: -----> Building dependencies
remote:        Installing node modules (package.json)
remote: 
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules
remote:        - bower_components (nothing to cache)
remote: 
remote: -----> Build succeeded!
remote:        ??? ejs@2.4.1 extraneous
remote:        ??? emailjs@1.0.8 extraneous
remote:        ??? express@4.13.3
remote:        ??? http-status@0.2.3
remote:        ??? nodemailer@1.4.0
remote:        ??? nodemailer-smtp-transport@1.0.4
remote:        ??? python-shell@0.4.0
remote:        ??? xoauth2@1.2.0
remote:        
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 13M
remote: -----> Launching...
remote:        Released v25
remote:        https://arcane-anchorage-33274.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
Run Code Online (Sandbox Code Playgroud)

Ret*_*old 9

尝试删除已弃用的heroku-buildpack-multi并使用Heroku buildpacks命令:

$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku buildpacks:add --index 2 heroku/python
Run Code Online (Sandbox Code Playgroud)


mar*_*dew 7

也许对某些人有用:如果您通过 GitHub(而不是通过 Heroku CLI)进行部署,您可以在 Heroku 仪表板的“设置”选项卡下添加其他语言的构建包。