Problem with importing fitz

I installed PyMuPDF in repl packages and import the fitz but when i used to run the code then it gives me error:

Traceback (most recent call last):
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/main.py", line 21, in <module>
    import fitz
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/.pythonlibs/lib/python3.10/site-packages/fitz/__init__.py", line 1, in <module>
    from frontend import *
ModuleNotFoundError: No module named 'frontend'
Traceback (most recent call last):
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/main.py", line 21, in <module>
    import fitz
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/.pythonlibs/lib/python3.10/site-packages/fitz/__init__.py", line 1, in <module>
    from frontend import *
ModuleNotFoundError: No module named 'frontend'
Traceback (most recent call last):
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/main.py", line 21, in <module>
    import fitz
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/.pythonlibs/lib/python3.10/site-packages/fitz/__init__.py", line 1, in <module>
    from frontend import *
ModuleNotFoundError: No module named 'frontend'
1 Like

Hi @IqbalAhmadi !
Try running poetry add frontend if it is a required module.
Is frontend a file or a module you need?

3 Likes

Hello,
click three dots and Show hidden files, then open .replit file and add this near the top:

disableGuessImports = true

Then, delete .pythonlibs folder.
Check pyproject.toml and ensure that there are no packages that you don’t use. If there are, remove their lines.
Then, run poetry update in the Shell.

3 Likes

i can help you with that

Instead of posting brief sentences, try being more lengthy and tell them what you’ll do.

4 Likes

Hi there!
Please post helpful content in your posts, instead of saying you can help. If you can help, please post a suggestion for the OP to solve their problem. If not, don’t post at all - it clutters the forum with unnecessary posts.
Thank you.

3 Likes

Hi @IqbalAhmadi !
Has any of the posts above helped you solved your problem?

1 Like

No its not solved but instead of fitz i use pyPDF2 and it worked but now i am troubled with importing tabula. I installed the library and the dependencies but in coding workspace i can’t use tabula methods

Traceback (most recent call last):
File “/home/runner/generate-a-PDF-from-an-excel-spreadsheet/main.py”, line 36, in
table=tabula.read_pdf(‘weather.pdf’, pages=1)
AttributeError: module ‘tabula’ has no attribute ‘read_pdf’

Try running in the shell pip install tabula-py or poetry add tabula-py.

They already did that:

Indeed, tabula-py requires extra dependencies. Installing it using the Packages tool would be more correct.
tabula might be usable by installing it in a different way if that doesn’t work:
Open the System dependencies tool and, if it allows, install python310Packages.tabula-py . There is also a bug that may break other python packages, so if there are ModuleNotFoundErrors, add this to the bottom of .replit file:

[env]
PYTHONPATH = "$PYTHONPATH:$REPL_HOME/.pythonlibs/lib/python3.10/site-packages"
2 Likes

tabula and tabula-py are different, at least from what I found.

1 Like

I’ve installed tabula-py and set your command in the .replit file after running the code i get error

and after that this error:
Traceback (most recent call last):
  File "/home/runner/generate-a-PDF-from-an-excel-spreadsheet/main.py", line 36, in <module>
    table=tabula.read_pdf('weather.pdf', pages=1)
AttributeError: module 'tabula' has no attribute 'read_pdf'

Looks like it’s actually failing to install the package, which is probably linked to your issues.

Hello, I believe the problem is the installed package tabula, which is not tabula-py, and is causing problems.

It also seems like the previous solution I provided is not necessary. You can optionally remove that code from .replit, and no system dependencies are needed. (The disableGuessImports = true is still needed though.)

Do this:
Open pyproject.toml file and delete the line tabula = "^1.0.5" .
Then, delete the .pythonlibs folder.
Run poetry update in the Shell. This should fix all the problems.

1 Like

thank you NuclearPasta0 it works. but i got new error about javanotfounderror:

Whoops, I guess the System dependency is actually needed. (Java is obviously not installed by default for python repls.)

Open the System dependencies tool and use it to install python310Packages.tabula-py .
Then, add this to the bottom of .replit file:

[env]
PYTHONPATH = "$PYTHONPATH:$REPL_HOME/.pythonlibs/lib/python3.10/site-packages"

Then, refresh or type kill 1 in the Shell.
This should probably fix all of the problems.

3 Likes

I’m sorry whether I install python310packages.tabula-py in system dependencies or packages tool because system dependencies doesn’t have any option or allow me to install.

Sometimes, the install functionality is not present in the System dependencies tool.
It can be installed manually though.

Create a file named replit.nix
Paste this code in:

{pkgs}: {
  deps = [
    pkgs.python310Packages.tabula-py
  ];
}

Refresh.
(I think there is also a shell command but I forgot it.)

2 Likes

Thank u so much dear NuclearPasto0 it has worked.