JoshData/pdf-diff

AttributeError: module 'diff_match_patch' has no attribute 'diff'

horror-vacui opened this issue · 6 comments

 $ pdf-diff journal.pdf journal_v3.pdf > comparison.png
Traceback (most recent call last):
  File "/usr/local/bin/pdf-diff", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/pdf_diff/command_line.py", line 497, in main
    changes = compute_changes(args.files[0], args.files[1], top_margin=float(args.top_margin), bottom_margin=float(args.bottom_margin))
  File "/usr/local/lib/python3.6/dist-packages/pdf_diff/command_line.py", line 17, in compute_changes
    diff = perform_diff(docs[0][1], docs[1][1])
  File "/usr/local/lib/python3.6/dist-packages/pdf_diff/command_line.py", line 122, in perform_diff
    return diff_match_patch.diff(
AttributeError: module 'diff_match_patch' has no attribute 'diff'

 $ pip3 install diff_match_patch
Requirement already satisfied: diff_match_patch in /usr/local/lib/python3.6/dist-packages (20181111)

I've got the the problem above on a Xubuntu 18.04.3 LTS machine witch python 3.6. pdf-diff version 0.9.1 was installed through pip. I am not sure how to debug it further, or what further information are needed to diagnose the error.

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import diff_match_patch
>>> dir(diff_match_patch)
['__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__packager__', '__path__', '__spec__', '__version__', 'diff_match_patch', 'patch_obj', 'sys']

Hi,

I have the same problem. Is it possible that you have a typo in the script?

image

Maybe it is diff_match_patch.diff_main instead of just diff_match_patch.diff?

hi, for windows there isn't anything like pdf-diff we have to install poppler and visual c++ 14.0 requirement, and then it works,
it is pip install diff_match_patch_python

This issue is caused by a name collision issue between diff_match_patch and diff_match_patch_python. This program requires diff_match_patch-python, but diff_match_patch is installed by default on many systems. I uninstalled diff_match_patch using pip uninstall diff_match_patch and it works as intended.

I'm on MacOS using a Conda environment with Python 3.9 installed.

I'm not sure if this is an optimal solution, as diff_match_patch seems to be a frequently used library, but it works for me.

It works for me if I change line 122 into diff_match_patch.diff_match_patch().diff_main

Use

pip uninstall diff_match_patch

and

pip install diff_match_patch_python
pip install pdf-diff

It works like a charm without any issue. readjfb your suggestions helped a lot in a pdf comparison project.