我正在尝试使用 camelot 从 pdf 中提取表格数据,但出现以下错误。
代码:
tables = camelot.read_pdf(file_name)
错误:
GhostscriptNotFound: Please make sure that Ghostscript is installed and available on the PATH environment variable
我已经安装了 Ghostscript,并且在 PATH 环境变量中可用。
请查看以下版本详细信息:
- Windows-10-10.0.17134-SP0
- Python 3.6.5 |Anaconda, Inc.| (默认,2018 年 3 月 29 日,13:32:41)[MSC v.1900 64 位 (AMD64)]
- NumPy 1.14.3
- openCV 3.4.3
- 柯莱特 0.3.2
请帮助解决这个问题。
请您参考如下方法:
将 Ghostscript 的“bin”和“lib”路径添加到 PATH 对我有用:
C:\Program Files\gs\gs9.26\binC:\Program Files\gs\gs9.26\lib
然后您需要应用该更改,具体取决于具体用例。
按严重程度排序
- 重启 Python - 这应该可以正常工作
- 让Python自动获取Gostscript并更新运行环境
- 如果可以并且作为最后的手段,请重新启动
一般情况下,无需进入运行 Python interpreter 的每个操作系统和每个环境(例如 Jupyter session 、 IDE 或 CLI ),重启通常是过度的。对于某些人来说,重启是不可能的。
在应用安装程序完成或您自己更改 PATH 后,只需关闭并重新打开您的环境(如上定义)。
没有什么可以阻止您使用 subprocess 更改您的 Python 脚本 中的 PATH用于安装附加应用程序或 os 的模块模块,或通过引用应用程序的绝对路径,例如
# Updating the current PATH inside Python
import os
from pathlib import Path
def update_app_path(app, new_path):
# Get the PATH environment variable
existing = [Path(p) for p in os.environ["PATH"].split(os.path.pathsep))
# Copy it, deleting any paths that refer to the application of interest
new_path = [e for e in existing if not Path(e/app).exists()]
# Append a the new entry
new_path.append(new_path)
# or you could use new_path.append(Path(new_path).parent)
# Reconstruct and apply the PATH
os.environ["PATH"] = os.path.pathsep.join(map(str, new_path))
这是因为 Python 在启动时获取当前环境的副本,之后它使用 os 或 shell 调用执行的任何操作都使用该复制的环境。改变 Python 内的环境不会改变用户在运行 Python 之外的环境,除非有意这样做,否则这种方式的改变不是永久性的。
