pymupdf/PyMuPDF

AttributeError("module 'fitz' has no attribute 'open'")

T4m opened this issue · 7 comments

T4m commented

Describe the bug (mandatory)

With the version 1.17.7, the basic fitz.open return the following error :
AttributeError("module 'fitz' has no attribute 'open'")

It is supposed to open a document as explained here: https://pymupdf.readthedocs.io/en/latest/tutorial.html

To Reproduce (mandatory)

Explain the steps to reproduce the behavior, For example, include a minimal code snippet, example files, etc.

  • Install latest tag (1.17.7)
  • Follow the tutorial documentation.

Your configuration (mandatory)

  • Linux buster64
  • Python 3.7
  • PyMuPDF 1.17.7 from pip install

Additional context (optional)

I could fix it by going back to version 1.16.14

Cannot reproduce:

sudo -H python3.8 -m pip install -U pymupdf
Collecting pymupdf
  Downloading PyMuPDF-1.17.7-cp38-cp38-manylinux2010_x86_64.whl (6.1 MB)
     |████████████████████████████████| 6.1 MB 156 kB/s
Installing collected packages: pymupdf
Successfully installed pymupdf-1.17.7
jorj@Dosadi:/mnt/d/Harald/Desktop$ ipython38
Python 3.8.5 (default, Jul 20 2020, 19:48:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import fitz

In [2]: doc=fitz.open()

In [3]: 

this error usually indicates that __init__.py wasn't executed. Which e.g. happens when you are in the installation fitz directory and start python.

T4m commented

Thank you for your answer,

It was indeed an installation issue.
I could fix it by completely rebuild my virtual environment.
👍

Today I am battling this error with fitz (PyMuPDF) 1.23.3 in Pycharm 2022.2.3 running on Windows 10 22H2.

Have you installed the package fitz by mistake?

Unfortunately there is an unrelated package called fitz on pypi.org that conflicts with package PyMuPDF, and pip doesn't seem to protect against this, despite these packages creating some of the same files in the Python installation.

I can get the error AttributeError: module 'fitz' has no attribute 'open' by doing:

pip install fitz
pip install pymupdf
pip uninstall fitz

For me, things can then be made to work with:

pip install --force-reinstall pymupdf

Could you try that?

pip install --force-reinstall pymupdf

This solved it for me. Thanks!