【问题标题】:How to fix 'Is poppler installed and in PATH?' in R如何修复“是否安装了 poppler 并在 PATH 中?”在 R 中
【发布时间】:2019-03-28 22:36:35
【问题描述】:

我正在使用 reticulate 在 R 中运行 python 脚本。我使用 py_discover_config() 来查找 Python 配置。我正在使用蟒蛇。我不太了解环境以及为什么需要环境。

我尝试使用 use_python() 和 use_condaenv() 甚至使用 conda_install 安装软件包。

library(tidyverse)
library(jsonlite)
library(reticulate)

py_discover_config()
# Set the path to the Python executable file
source_python("~/projects/stiekemthuis/API.py")

json_list <- api_fun() %>% toJSON()

导入python库没有问题:

from pdf2image import convert_from_path
import numpy as np
from pathlib import Path
import io, json
import os
from PIL import Image
import requests
import sys

我在第 25 行遇到错误:

pages = convert_from_path(files[0], 300)

py_call_impl(callable, dots$args, dots$keywords) 中的错误: PDFInfoNotInstalledError:无法获取页数。 poppler 是否已安装并在 PATH 中?

我试图将 wd() 设置为 poppler 二进制文件的路径。 可以做什么?

【问题讨论】:

标签: python r poppler reticulate


【解决方案1】:

我停止使用库(网状)并开始使用system2通过python命令直接执行,后跟脚本路径:

command = "python"
allArgs = c(path2script)

output = system2(command, args=allArgs, stdout=TRUE)

json_list <-output %>% fromJSON()

我在我的 python 脚本中使用了另一个线程的代码:

print(json.dumps(res, sort_keys=False, indent=2, separators=(',', ': ')))

因为我的 Json 字符串格式不好。

【讨论】:

    猜你喜欢
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2013-08-25
    • 1970-01-01
    • 2020-11-25
    • 2021-09-08
    相关资源
    最近更新 更多