Node app with Python module in project on Heroku n

2019-02-19 06:37发布

I have a Node (Express server) project deployed to Heroku which runs fine, but I have a small Python module I wrote that doesn't need a server or new Heroku instance, but it needs to install some 3rd party packages from pip.

My problem is that while Python seems to run fine (a print() works in .py file perfectly) it doesn't install the modules. I ran pip freeze and added the requirements.txt file to the root of my project. The file looks like:

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

But when I deploy Heroku doesn't detect any python and doesn't seem to install them and I get:

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' 

The output from 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===

I also tried adding a "pipinstall" worker to see if it would install but nothing happened.

Procfile:

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

1条回答
劫难
2楼-- · 2019-02-19 07:06

You need multiple buildpacksfor your app.

Run the following:

heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi

Then, add the following in a file called .buildpacks in your project's root directory:

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

Alternatively, you can use heroku toolbelt commands (heroku buildpacks:set and heroku buildpacks:add) to configure your multiple buildpacks, as described here.

查看更多
登录 后发表回答