如何在 Heroku 中的 Python 服务器上执行 "g++" 命令?
How to execute a "g++" command on a Python server in Heroku?
我正在尝试将Python服务器部署到Heroku,我需要在其中一个库上执行"g ++"命令才能将其安装在服务器上。
我想创建一个 gunicorn 和 Flask 服务器,从跨语言模型保留 : 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++:未找到"作为输出。
此外,命令"哪个 g++"不返回任何内容,但"哪个 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
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 执行函数时导致崩溃的变量
- 无论条件是否为true,if总是在c++中执行
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 在C++中对T*类型执行std::move的意外行为
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何在没有信号的情况下从C++执行QML插槽
- 如何确认我的constexpr表达式实际上已经在编译时执行
- C++17中的并行执行策略
- QML按钮点击功能执行顺序
- 程序在执行程序的其余部分之前退出
- 为什么catch中的代码没有被执行
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 将执行、作业和WinAPI相乘
- 对字符数组中的元素执行逐位操作
- 为什么g++在未执行的代码处标记强制转换错误
- 如何使用原子指针执行双缓冲