B4J Question [PyBridge] how install libraries??

behnam_tr

Active Member
Licensed User
Longtime User
I have a problem installing Python libraries. I tested both from Python Global and Python Local. The library installs successfully but I get an error when running.

b4j log:
B4X:
(RuntimeException) java.lang.RuntimeException: (b4xmainpage._htmltopdf) - Python Error (ModuleNotFoundError) - Method: module.exec: No module named 'fpdf'

install log:
B4X:
pip install fpdf2

Requirement already satisfied: fpdf2 in c:\users\admin\downloads\compressed\pyfp
df\b4j\objects\python\python\lib\site-packages (2.8.2)
Requirement already satisfied: defusedxml in c:\users\admin\downloads\compressed
\pyfpdf\b4j\objects\python\python\lib\site-packages (from fpdf2) (0.7.1)
Requirement already satisfied: Pillow!=9.2.*,>=6.2.2 in c:\users\admin\downloads
\compressed\pyfpdf\b4j\objects\python\python\lib\site-packages (from fpdf2) (11.
1.0)
Requirement already satisfied: fonttools>=4.34.0 in c:\users\admin\downloads\com
pressed\pyfpdf\b4j\objects\python\python\lib\site-packages (from fpdf2) (4.55.8)

os : win 8.1
b4j : v10.2
pybridge :v1.0
jdk : 19

I checked all three runtimes.
1.https://github.com/adang1345/PythonWin7/tree/master/3.13.2
2.b4j internal python runtime
3.https://github.com/winpython/winpython/releases/tag/13.1.202502222final
 
Last edited:
Solution
Just guessing, but the output refers to a local python. Maybe the program is trying to use the global python which maybe doesnt have fpdf2 installed.

Do you have a global python installed?

If you do, try opening a cmd window (real one not one from IDE) and doing the pip install fpdf2 - then try the program again.

behnam_tr

Active Member
Licensed User
Longtime User
What does

pip show fpdf2

output?
B4X:
Name: fpdf2
Version: 2.8.2
Summary: Simple & fast PDF generation for Python
Home-page: https://py-pdf.github.io/fpdf2/
Author: Olivier PLATHEY ported by Max
Author-email:
License: LGPL-3.0-or-later
Location: C:\Users\Admin\Downloads\Compressed\PyFPDF\B4J\Objects\python\python\L
ib\site-packages
Requires: defusedxml, fonttools, Pillow
Required-by:
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Just guessing, but the output refers to a local python. Maybe the program is trying to use the global python which maybe doesnt have fpdf2 installed.

Do you have a global python installed?

If you do, try opening a cmd window (real one not one from IDE) and doing the pip install fpdf2 - then try the program again.
 
Upvote 0
Solution

behnam_tr

Active Member
Licensed User
Longtime User
Just guessing, but the output refers to a local python. Maybe the program is trying to use the global python which maybe doesnt have fpdf2 installed.

Do you have a global python installed?

If you do, try opening a cmd window (real one not one from IDE) and doing the pip install fpdf2 - then try the program again.
Yes, that was exactly the problem. I had installed Python before and I didn't remember. I uninstalled it and the problem was solved. But why does this problem occur and what is the solution?

When we set the Python path in b4j, why should it depend on the Python installed on the system?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Maybe the path here wasn't correct:
B4X:
Dim opt As PyOptions = Py.CreateOptions("Python/python/python.exe")

It first searches this path (the local Python) and if not it uses the global Python which is the Python set under Tools - Configure Paths. Technically it works by getting the B4J_PYTHON environment variable which is set by the IDE.
 
Upvote 0
Top