Closed sharoseali closed 6 months ago
If they are not shipping poppler-qt5 binary wheel, it is almost impossible to install.
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
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:.
FYI, I am making an executable of this project to run it on Windows.
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.
So we have to make the same spec file here as well as inside this project. Can you please elaborate more?
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.
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.
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
the executable built on Linux VM will can only be run in Linux based os, not Windows.
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 ??😐
The only way to run under windows is building the python-poppler-qt5 dependency. Which is extremely difficult.
If it is ported to any other cross platform library (eg. mupdf), it can be packaged under windows.
So you mean excluding popplerQt dependency and using alternate (muPDF) ?
So you mean excluding popplerQt dependency and using alternate (muPDF) ?
Yes
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
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.
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.
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.
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))
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.
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.
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
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
Sorry if you find massive comments in the code, as I am struggling to make tests.
Wait until I finish creating PdfDocument wrapper.
check this main.py.zip
copy text, link annotations not working yet. outlines working fine.
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?
So, is the wrapper merged into the main repo?
Yes, after we make sure everything works fine, It will be merged into main repo.
@ksharindam Also working on Windows. Thanks 👍
@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.
I have installed Appimage. Worked completely fine. Thanks for updating the git and for uploading executables. Inspiring work
👍 👍
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.I have also tried different other options mentioned in the official repo of python3-poppler-qt5 but no success.