1

我正在使用 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 二进制文件的路径。可以做什么?

4

1 回答 1

0

我停止使用库(网状)并开始使用 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 字符串格式不好。

于 2019-03-29T14:11:40.363 回答