pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
5.19k stars 496 forks source link

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

Closed T4m closed 1 year ago

T4m commented 4 years ago

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.

Your configuration (mandatory)

Additional context (optional)

I could fix it by going back to version 1.16.14

JorjMcKie commented 4 years ago

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]: 
JorjMcKie commented 4 years ago

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 4 years ago

Thank you for your answer,

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

gnash1 commented 1 year ago

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

julian-smith-artifex-com commented 1 year ago

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?

gnash1 commented 1 year ago

I just posted my entire journey here: https://github.com/pymupdf/PyMuPDF/issues/2681 Please test the code samples. All you have to do is load them in PyCharm and the error will be visually and immediately obvious.

On Thu, Sep 21, 2023 at 4:48 AM Julian Smith @.***> wrote:

Reopened #660 https://github.com/pymupdf/PyMuPDF/issues/660.

— Reply to this email directly, view it on GitHub https://github.com/pymupdf/PyMuPDF/issues/660#event-10432952977, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIABZMLLQOP7WVR4LB5VSNDX3QENBANCNFSM4RR2UGSA . You are receiving this because you commented.Message ID: @.***>

thomasahle commented 7 months ago
pip install --force-reinstall pymupdf

This solved it for me. Thanks!