2016-03-22 84 views
2

我有一個Node(Express服務器)項目部署到Heroku,它運行良好,但我有一個小的Python模塊,我不需要服務器或新的Heroku實例,但它需要從pip安裝一些第三方軟件包。Heroku上的項目中沒有安裝Python模塊的節點應用程序

我的問題是,雖然Python似乎運行良好(print()完美工作在.py文件中),但它不安裝模塊。我運行pip freeze並將requirements.txt文件添加到我的項目的根目錄中。該文件看起來像:

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

但是當我部署的Heroku沒有檢測到任何蟒蛇似乎並沒有安裝它們,我得到:

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) 

     > [email protected] 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! 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     ├── [email protected] 
     └── [email protected] 

-----> Discovering process types 
     Procfile declares types -> web 
-----> Compressing... 
     Done: 30M 
-----> Launching... 
     Released v13 
     https://my-project.herokuapp.com/ deployed to Heroku 

=== UPDATE ===

我也嘗試添加了「pipinstall」工人,看它是否會安裝,但沒有公頃ppened。

Procfile:

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

回答

2

您需要多個buildpacksfor您的應用程序。

運行以下命令:

Heroku的配置:設置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 buildpack:add)來配置您的多個buildpack,如here所述。

+0

這就是我的做法,但根據Heroku的Python指南(https://devcenter.heroku.com/),正式支持SciPy(其正在嘗試安裝)文章/蟒蛇-C-DEPS)。看起來有一個[解決方法](https://github.com/thenovices/heroku-buildpack-scipy),但只是使用Node和Python buildpacks正在推動dyno內存限制。 –

相關問題