我有一个部署到Heroku的Node(Express服务器)项目运行正常但是我有一个小的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
答案 0 :(得分:2)
您的应用需要多个buildpack。
运行以下命令:
heroku config:设置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)来配置多个构建包,如here所述。