ksharindam / gospel-pdf-viewer

Poppler based fast pdf viewer written in PyQt5
GNU General Public License v3.0
9 stars 4 forks source link

python3-poppler-qt5 Dependency Installing Error (Windows) #5

Closed sharoseali closed 6 months ago

sharoseali commented 7 months ago

HI there, Thanks for your great work.

I want to run the tool on Windows 10. But while installing dependencies, python3-poppler-qt5 I got in trouble. I have installed using pip with command pip install python-poppler-qt5 but after waiting for a long time, I got an error.

pip install python-poppler-qt5
Collecting python-poppler-qt5pip install python-poppler-qt5
Collecting python-poppler-qt5
  Using cached python-poppler-qt5-21.3.0.tar.gz (28 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [30 lines of output]
      Querying qmake about your Qt installation...
      'pkg-config' is not recognized as an internal or external command,
      operable program or batch file.
      pyproject.toml: line 5: using '[tool.sip.metadata]' to specify the project metadata is deprecated and will be removed in SIP v7.0.0, use '[project]' instead
      Traceback (most recent call last):
        File "c:\users\shahzeb\anaconda3\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "c:\users\shahzeb\anaconda3\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "c:\users\shahzeb\anaconda3\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 152, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\api.py", line 46, in build_wheel
          project = AbstractProject.bootstrap('wheel',
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 87, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\project.py", line 587, in setup
          self.apply_user_defaults(tool)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\pyqtbuild\project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\project.py", line 240, in apply_user_defaults
          bindings.apply_user_defaults(tool)
        File "project.py", line 50, in apply_user_defaults
          cflags = self.run_pkg_config('--cflags-only-I').split()
        File "project.py", line 43, in run_pkg_config
          output = subprocess.check_output(
        File "c:\users\shahzeb\anaconda3\lib\subprocess.py", line 415, in check_output
          return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
        File "c:\users\shahzeb\anaconda3\lib\subprocess.py", line 516, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command '['pkg-config', '--cflags-only-I', 'poppler-qt5']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

  Using cached python-poppler-qt5-21.3.0.tar.gz (28 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [30 lines of output]
      Querying qmake about your Qt installation...
      'pkg-config' is not recognized as an internal or external command,
      operable program or batch file.
      pyproject.toml: line 5: using '[tool.sip.metadata]' to specify the project metadata is deprecated and will be removed in SIP v7.0.0, use '[project]' instead
      Traceback (most recent call last):
        File "c:\users\shahzeb\anaconda3\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "c:\users\shahzeb\anaconda3\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "c:\users\shahzeb\anaconda3\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 152, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\api.py", line 46, in build_wheel
          project = AbstractProject.bootstrap('wheel',
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 87, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\project.py", line 587, in setup
          self.apply_user_defaults(tool)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\pyqtbuild\project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "C:\Users\Shahzeb\AppData\Local\Temp\pip-build-env-0_pbo7np\overlay\Lib\site-packages\sipbuild\project.py", line 240, in apply_user_defaults
          bindings.apply_user_defaults(tool)
        File "project.py", line 50, in apply_user_defaults
          cflags = self.run_pkg_config('--cflags-only-I').split()
        File "project.py", line 43, in run_pkg_config
          output = subprocess.check_output(
        File "c:\users\shahzeb\anaconda3\lib\subprocess.py", line 415, in check_output
          return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
        File "c:\users\shahzeb\anaconda3\lib\subprocess.py", line 516, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command '['pkg-config', '--cflags-only-I', 'poppler-qt5']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I have also tried different other options mentioned in the official repo of python3-poppler-qt5 but no success.

ksharindam commented 7 months ago

If they are not shipping poppler-qt5 binary wheel, it is almost impossible to install.

sharoseali commented 7 months ago

Hi @ksharindam

Actually, I have started to build an executable file of gospel-pdf on Ubuntu. The executable file is successfully built, but when i run it, it's creating an issue

Traceback (most recent call last): File "gospel_pdf/main.py", line 21, in ModuleNotFoundError: No module named 'resources_rc' [2095958] Failed to execute script'main' due to unhandled exception!

Before, it was giving the same error for ui_window.py and PyQt5.QtXml

Then I tried to run the following command: pyinstaller --name floorPlan --hidden-import PyQt5.QtWidgets --hidden-import PyQt5.QtXml --onefile main.py The output is

 File "gospel_pdf/main.py", line 21, in <module>
ModuleNotFoundError: No module named 'resources_rc'

Any help here? Here is the complete process I followed:.

  1. I installed all the requirements as mentioned in the repo. The code is running with python3 main.py
  2. installed pyinstaller with pip3 install pyinstaller
  3. Then I build the main.py file: pyinstaller --name pdf-reader --onefile main.py
  4. After successful build, I run pdef-reader executable present in dist folder ./pdf-reader or sudo ./pdfreader and here the error comes

FYI, I am making an executable of this project to run it on Windows.

ksharindam commented 7 months ago

that's because of the line sys.path.append(os.path.dirname(__file__)) # for enabling python 2 like import

See my chemcanvas project. Under Windows directory, see the 'pathex' variable in spec file.

sharoseali commented 7 months ago

So we have to make the same spec file here as well as inside this project. Can you please elaborate more?

ksharindam commented 7 months ago

To enable python 2 like import, this program changes the PATH environment variable. pyinstaller parses the main.py file and check which files are imported, then those files are merged. pyinstaller can not detect the path added by sys.path.append() even though it is same directory as main.py. So, we need to tell pyinstaller that the directory must be added. It can be done both via commandline args and spec file. I use spec file because I don't have to remember or save the whole command every time I package the app.

ksharindam commented 7 months ago

you can build it by ... pyinstaller --name pdf-reader --paths . --onefile main.py

as pyinstaller documentation says ...

-p DIR, --paths DIR A path to search for imports (like using PYTHONPATH). Multiple paths are allowed, separated by ':', or use this option multiple times. Equivalent to supplying the pathex argument in the spec file.

sharoseali commented 7 months ago

I have commented the line sys.path.append(os.path.dirname(__file__)) # for enabling python 2 in main.py and run the command pyinstaller --name pdf-reader --paths . --onefile main.py After running the build file, I got:

root@DESKTOP-BMBLATB:~/gospel-pdf-viewer/gospel_pdf/dist# ./pdf_reader
Traceback (most recent call last):   File "main.py", line 9, in <module>                                                                                                                               File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module   
File "main.py", line 20, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtXml' 
[8365] Failed to execute script 'main' due to unhandled exception! 

Then I run with this command, and this time-generated buid works successfully:

#root@DESKTOP-BMBLATB:~/gospel-pdf-viewer/gospel_pdf/dist# pyinstaller --name floorPlan --hidden-import PyQt5.QtWidgets --hidden-import PyQt5.QtXml --path . --onefile main.py

I am running these commands on a VM installed on Windows 10. Now the issue is how can I run this build (generated on a Linux VM) on Windows? Is that possible? @ksharindam Thanks a lot

ksharindam commented 7 months ago

the executable built on Linux VM will can only be run in Linux based os, not Windows.

sharoseali commented 7 months ago

Seems I miss-understood something. I read one blog saying about executables generated by VMs running on Windows are cross platform. But its not working

Any directions ??😐

ksharindam commented 7 months ago

The only way to run under windows is building the python-poppler-qt5 dependency. Which is extremely difficult.

ksharindam commented 7 months ago

If it is ported to any other cross platform library (eg. mupdf), it can be packaged under windows.

sharoseali commented 7 months ago

So you mean excluding popplerQt dependency and using alternate (muPDF) ?

ksharindam commented 7 months ago

So you mean excluding popplerQt dependency and using alternate (muPDF) ?

Yes

sharoseali commented 7 months ago

Hi @ksharindam Thanks for your guidance so far. After your last comment, I started changing the python-popular-qt5 base code to PyMuPDF Equilent. I commented on a previous function that uses Poppler and writes new functions in my updated GUI. Now the GUI is loading, but when I load the PDF in the GUI,. It's not rendering the PDF document. Secondly, I am not getting any error responses on my terminal. I'm attaching my code snippet. Kindly have a look. test_MU_pdf.zip

ksharindam commented 7 months ago

under Renderer.render(),

   img = page.get_pixmap(matrix=fitz.Matrix(int(dpi / 72.0), int(dpi / 72.0)))
   qimage = QImage(img.samples, img.width, img.height, img.stride, QImage.Format_RGB32)

the returned qimage is a null image.

ksharindam commented 7 months ago

img.samples returns python bytes, but the initializer you used expects a pointer. replacing the line with qimage = QImage(img.samples, img.width, img.height, QImage.Format_RGB888) can render the image. But the size is smaller.

ksharindam commented 7 months ago

After more experimenting, i found your function works with just changing the image format. qimage = QImage(img.samples, img.width, img.height, img.stride, QImage.Format_RGB888)

and omitting the stride does not work in many cases.

ksharindam commented 7 months ago

Fixed the scaling issue by replacing the line img = page.get_pixmap(matrix=fitz.Matrix(int(dpi / 72.0), int(dpi / 72.0))) with img = page.get_pixmap(dpi=int(dpi))

sharoseali commented 7 months ago

After more experimenting, i found your function works with just changing the image format. qimage = QImage(img.samples, img.width, img.height, img.stride, QImage.Format_RGB888)

and omitting the stride does not work in many cases.

This works . Now document is rendering..but sometimes the windows get crash. For now the ongoing issues are:

Selecting fixed width button crashes application The content list of documents, is not working well . Sometimes it appear as non responsive and sometimes it works for some docs. Also there is an issue in Qpainter() coming at windows side.

ksharindam commented 7 months ago

but sometimes the windows get crash

by 'sometimes' do you mean for some particular pdfs?

I am creating a separate PdfDocument class as a wrapper of both pymupdf and poppler library. So both libraries will be supported.

sharoseali commented 7 months ago

by 'sometimes' do you mean for some particular pdfs? Yes in Windows

I am creating a separate PdfDocument class as a wrapper of both pymupdf and poppler library. So both libraries will be supported.

👍 Great

sharoseali commented 7 months ago

HI @ksharindam One thing I'm stuck on is that after loading a document with Fitz, the GUI crashes without showing an error message on Windows OS. However, transferring back to Linux gives a segmentation error and crashes. While debugging, I found a problem on line number 817:'self.treeView.header().setStretchLastSection(False) in getOutlines function, in my main.py

test_main.zip

Sorry if you find massive comments in the code, as I am struggling to make tests.

ksharindam commented 7 months ago

Wait until I finish creating PdfDocument wrapper.

ksharindam commented 6 months ago

check this main.py.zip

copy text, link annotations not working yet. outlines working fine.

sharoseali commented 6 months ago

Thanks, @ksharindam . Great efforts. Yes, it worked fine. I have checked it on Linux. Will run on Windows asap and will update.

Wait until I finish creating the PdfDocument wrapper.

So, is the wrapper merged into the main repo?

ksharindam commented 6 months ago

So, is the wrapper merged into the main repo?

Yes, after we make sure everything works fine, It will be merged into main repo.

sharoseali commented 6 months ago

@ksharindam Also working on Windows. Thanks 👍

ksharindam commented 6 months ago

@sharoseali I have uploaded the exe package and AppImage in releases page. try them. run the AppImage by mark it executable and then double click.

sharoseali commented 6 months ago

I have installed Appimage. Worked completely fine. Thanks for updating the git and for uploading executables. Inspiring work
👍 👍