gpt4 book ai didi

python - 如何在 Heroku 中的 Python 服务器上执行 "g++"命令?

转载 作者:行者123 更新时间:2023-11-28 04:16:15 25 4
gpt4 key购买 nike

我正在尝试将 Python 服务器部署到 Heroku,我需要在其中一个库上执行“g++”命令以将其安装到服务器上。

我想创建一个 gunicorn 和 Flask 服务器托管 facebook 的跨语言模型预留 XLM 模型:https://github.com/facebookresearch/XLM

该模型需要“fastBPE”库(https://github.com/glample/fastBPE),需要使用以下命令安装:g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast

但是,由于 Heroku 服务器是为 Python 配置的,它无法识别“g++”命令。

到目前为止,这是我尝试过的:- 在 Heroku 中添加构建包“heroku-buildpack-apt”并在我的源文件中创建一个“Aptfile”,在其中写入“g++”以及“build-essential”- 在主 python 文件中,我创建了一个子进程来启动“apt-get install g++”:

import subprocess
process = subprocess.Popen("apt-get install g++", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(output, err) = process.communicate()
#This makes the wait possible
p_status = process.wait()
#This gives the output of the command being executed
print("Command apt-get output: ",output)

但是,每当我运行以下子进程来安装 fastBPE 包时:

import subprocess
process = subprocess.Popen("g++ -std=c++11 -pthread -O3 tools/fastBPE/fastBPE/main.cc -IfastBPE -o tools/fastBPE/fast", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(output, err) = process.communicate()
p_status = process.wait()
print("Command apt-get output: ",output)

我系统地得到“g++: not found”作为输出。

此外,命令“which g++”不返回任何内容,但“which gcc”返回“/usr/bin/gcc”,因此安装了 gcc 而不是 g++

最佳答案

我最终设法弄明白了。

对于后代,有 2 种解决方案对我有用:

1 - 不太好的方法是在与 Heroku 服务器环境完全相同的 Linux 计算机上执行 g++ 命令,将其推送到 Heroku 并确保以后永远不会修改它。然后您可以使用上面的子流程调用 fastBPE ==> 它可以工作,但它更像是一个 DIY 不稳定的解决方案。关联的 GitHub 主文件是 https://github.com/Tony4469/xlm-agir/blob/master/mlm_tlm_prod.py

2 - 最好的解决方案是在带有 Miniconda 环境的 Docker 容器上预编译所有内容,您可以安装并运行所有必要的命令,然后轻松将其推送到 heroku。您可以在此处找到我使用的 Dockerfile: https://github.com/Tony4469/laser-agir/blob/master/Dockerfile

关于python - 如何在 Heroku 中的 Python 服务器上执行 "g++"命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56540601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com