python-3.x - 当 call tabula 遇到 Error : Cannot create file C:\Users

标签 python-3.x

问题是我尝试使用 tabula 阅读 PDF,首先我使用 tabula.environment_info() 来检查我的环境,它显示正常

然后我尝试阅读一些pdf

df = tabula.read_pdf("./input/CELCOM.pdf")

然后似乎尝试在临时文件夹中创建一些文件,然后我遇到了这个

Error: Cannot create file C:\Users\C00427~1\AppData\Temp\tmpinxwkue0
Error: 

Traceback (most recent call last):
  File "D:/04Coding/New folder/test.py", line 206, in <module>
    df = tabula.read_pdf("./input/"+str(each_file), spreadsheet=True, pages=each_tuple[0], multiple_tables=True)
  File "C:\Python37\lib\site-packages\tabula\wrapper.py", line 150, in read_pdf
    output = _run(java_options, kwargs, path, encoding)
  File "C:\Python37\lib\site-packages\tabula\wrapper.py", line 67, in _run
    return subprocess.check_output(args)
  File "C:\Python37\lib\subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "C:\Python37\lib\subprocess.py", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['java', '-Dfile.encoding=UTF8', '-jar', 'C:\\Python37\\lib\\site-packages\\tabula\\tabula-1.0.3-jar-with-dependencies.jar', '--pages', '1', '--lattice', '--guess', '--format', 'JSON', '--outfile', 'C:\\Users\\C00427~1\\AppData\\Temp\\tmpinxwkue0', './input/CELCOM.pdf']' returned non-zero exit status 1.

貌似是调用java做了什么,其实执行这行就出现了这个问题, 以 Popen(*popenargs, **kwargs) 作为进程:

当我使用 os.system('java -Dfile.encoding=UTF8 -jar C:\Python37\lib\site-packages\tabula\tabula-1.0.3-jar-with-dependencies.jar --pages 1 --lattice --guess --format JSON --outfile C:\Users\C00427~1\AppData\Temp\tmpbg5u94xu ./input/CELCOM.pdf')

要做到这一点,返回0,所以我觉得没问题,我不知道为什么Popen有这个问题

Python version:
    3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)]
Java version:
    java version "11.0.4" 2019-07-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)
tabula-py version: 1.4.0
platform: Windows-10-10.0.17134-SP0

最佳答案

这是 tabula-py 版本 1.4.0 中的一个已知问题,请参阅 https://github.com/chezou/tabula-py/issues/169更多细节。我遇到了同样的问题,并且能够通过从 tabula-py 1.4.0 升级到几天前刚刚发布的 1.4.1 来解决它。尝试:

pip uninstall tabula-py
pip install tabula-py

或您用来替换您环境中的库的任何方法。

关于python-3.x - 当 call tabula 遇到 Error : Cannot create file C:\Users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57362645/

相关文章:

Python字符串匹配并为不匹配的字符串给出重复的数字

python - 字典中类内的函数

python - PyCharm 无法访问/usr/lib/和/usr/bin/中的文件

python-3.x - 在客户端应用程序上将一个套接字与多个窗口一起使用

python - 如何修复 'DMatrix/Booster has not been intialized or has already been disposed ' 错误

python-3.x - 如何使用django Rest框架删除self forienkey中最多n种类型的数据?

python - 如何在 Scipy 中实现日志均匀分布?

python - 如何删除 Pandas 数据框中带有 NaN 的行?

python - 在 python3 中使用 os.walk 时文件读取不正确

python - os.walk 函数的问题