如何在heroku节点服务器上添加python依赖项

如何在heroku节点服务器上添加python依赖项

本文介绍了如何在heroku节点服务器上添加python依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Node的Heroku应用,但我需要能够在此服务器上运行Python脚本。我正在尝试安装我的Python依赖项,但无法使其正常工作。

I have a Heroku app that's running Node, but I need to be able to run Python scripts on this server. I'm trying to install my Python dependencies but can't get it to work.

我已经在项目中添加了python和node build包,创建一个虚拟环境并成功安装了requirements.txt,但是我继续遇到找不到模块的错误。

I've added both python and node build packs to my project, I've create a virtual environment and successfully installed requirements.txt, but I continue to get module not found errors.

如何在Heroku Node服务器上正确安装Python软件包?

How can I properly install Python packages on a Heroku Node server?

Heroku显示我已经正确设置了两个buildpack:

Heroku shows that I have correctly set both buildpacks:

heroku buildpacks --app <my app>

输出:

1. heroku/nodejs
2. heroku/python

如果我尝试安装Requirements.txt:

If I try to install requirements.txt:

$ pip install -r requirements.txt

说要求已经满足。我猜这与我的本地环境有关。

It says the requirements are already satisfied. I'm guessing this is in reference to my local environment.

Requirement already satisfied (use --upgrade to upgrade): requests==2.7.0 in /Library/Python/2.7/site-packages (from -r requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4==4.5.3 in /Library/Python/2.7/site-packages (from -r requirements.txt (line 2))

但是如果我尝试运行Python脚本,则会出现无模块错误:

But if I try to run my Python script, I get a no module error:


推荐答案

我已经解决了它:


  1. 我创建了(如果没有)文件 requirements.txt直接进入入口点的根目录(在我的情况下为index.js)

  2. 我手动添加了具有特定版本的库进入文件,在我的情况下是这样的:

  1. I created (If there is not) the file "requirements.txt" directly into the root of the entrypoint (index.js, in my case)
  2. I manually added the libraries with the specific versions into the file, in my case like this:

requests==2.7.0
beautifulsoup4==4.5.3


  • 我使用以下命令创建了 runtime.txt文件(如果没有)一行:我需要的python版本:

  • I created (If there is not) the file "runtime.txt" with with just one line: the python version i need, in my case:

    python-2.7.14
    


  • 我使用以下两个命令创建了multibuildpack:

  • I created the multibuildpacks with the two commands:

    heroku buildpacks:set heroku/python
    heroku buildpacks:add --index 1 heroku/nodejs
    


  • 最后,我继续执行git命令:

  • Finally, I continued with the git commands:

    git add requirements.txt runtime.txt
    git commit requirements.txt runtime.txt -m "requirements"
    git push heroku master
    


  • 这篇关于如何在heroku节点服务器上添加python依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-01 21:47