pdf-diff icon indicating copy to clipboard operation
pdf-diff copied to clipboard

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

Open horror-vacui opened this issue 5 years ago • 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']

horror-vacui avatar Jan 16 '20 13:01 horror-vacui

Hi. Unfortunately I'm not able to spend time on this project these days. I appreciate the bug report but probably won't be able to fix it (at least not until I need this project next).

On January 16, 2020 8:11:51 AM EST, horror-vacui [email protected] wrote:

$ 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']

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/JoshData/pdf-diff/issues/39

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

JoshData avatar Jan 17 '20 14:01 JoshData

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?

Grandement avatar Jan 28 '20 10:01 Grandement

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

SaiSandeepKantareddy avatar Dec 03 '20 06:12 SaiSandeepKantareddy

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.

readjfb avatar Sep 03 '21 07:09 readjfb

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

ErqingLi avatar Oct 21 '21 03:10 ErqingLi

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.

Vetrivel-PS avatar Mar 29 '22 08:03 Vetrivel-PS