Heroku上的项目中的Python模块节点应用程序不安装

我有一个Node(Express服务器)项目部署到Heroku运行良好,但我有一个小的Python模块,我不需要一个服务器或新的Heroku实例,但它需要从PIP安装一些第三方包。

我的问题是,虽然Python似乎运行良好(一个print()完全在.py文件中工作),它不会安装模块。 我运行pip freeze并将requirements.txt文件添加到我的项目的根目录。 该文件如下所示:

 funcy==1.6 numpy==1.10.2 scipy==0.16.1 

但是,当我部署Heroku没有检测到任何python,似乎并没有安装它们,我得到:

 Traceback (most recent call last): File "src/blm/algo.py", line 4, in <module> from package import mvo File "/app/src/blm/package/mvo.py", line 1, in <module> import numpy as np ImportError: No module named 'numpy' 

Heroku的输出

 -----> Using set buildpack heroku/nodejs -----> Node.js app detected -----> Creating runtime environment NPM_CONFIG_LOGLEVEL=error NPM_CONFIG_PRODUCTION=true NODE_ENV=production NODE_MODULES_CACHE=true -----> Installing binaries engines.node (package.json): unspecified engines.npm (package.json): unspecified (use default) Resolving node version (latest stable) via semver.io... Downloading and installing node 5.8.0... Using default npm version: 3.7.3 -----> Restoring cache Loading 2 from cacheDirectories (default): - node_modules - bower_components (not cached - skipping) -----> Building dependencies Pruning any extraneous modules Installing node modules (package.json) > my-project@0.0.1 postinstall /tmp/build_c845357a6a491eb02f8ad4b043020ac6/my-project-7f7e7fe8632473e1f1f88f430b040396fb10671f > webpack --config ./webpack-production.config.js --progress --colors Hash: 2ceaeac5876ff2e2463e Version: webpack 1.12.14 Time: 15178ms Asset Size Chunks Chunk Names bundle.js 455 kB 0 [emitted] main main.css 15 kB 0 [emitted] main + 272 hidden modules Child extract-text-webpack-plugin: + 2 hidden modules -----> Caching build Clearing previous node cache Saving 2 cacheDirectories (default): - node_modules - bower_components (nothing to cache) -----> Build succeeded! ├── babel-core@6.7.2 ├── babel-loader@6.2.4 ├── babel-preset-es2015@6.6.0 ├── babel-preset-react@6.5.0 ├── babel-preset-stage-0@6.5.0 ├── bcrypt@0.8.5 ├── css-loader@0.23.1 ├── d3@3.5.16 ├── d3pie@0.1.9 ├── express@4.13.4 ├── extract-text-webpack-plugin@1.0.1 ├── jquery@2.2.2 ├── node-sass@3.4.2 ├── node-uuid@1.4.7 ├── react@0.14.7 ├── react-dom@0.14.7 ├── react-redux@4.4.1 ├── react-router@2.0.1 ├── redux@3.3.1 ├── sass-loader@3.2.0 ├── style-loader@0.13.0 └── webpack@1.12.14 -----> Discovering process types Procfile declares types -> web -----> Compressing... Done: 30M -----> Launching... Released v13 https://my-project.herokuapp.com/ deployed to Heroku 

=== UPDATE ===

我也尝试添加一个“pipinstall”工作,看看是否会安装,但没有发生。

Procfile:

 web: node server.js pipinstall: pip install -r requirements.txt 

您需要为您的应用程序提供多个构build包。

运行以下命令:

herokuconfiguration:设置BUILDPACK_URL = https://github.com/ddollar/heroku-buildpack-multi

然后,将以下内容添加到项目根目录中名为.buildpacks的文件中:

 https://github.com/heroku/heroku-buildpack-python.git https://github.com/heroku/heroku-buildpack-nodejs.git 

或者,您可以使用heroku toolbelt命令(heroku buildpacks:set和heroku buildpacks:add)来configuration您的多个buildpack,如此处所述。