Assume I need to select PyBridge library,so I check the PyBridge library in the Libraries list.
I would like to know how I check that I have selected the PyBridge library yet via my code.
My taught is
I would like to know how I check that I have selected the PyBridge library yet via my code.
My taught is
B4X:
If IsUsed("PyBridge" ) then
#Region PythonConnected
Py.Initialize(Me, "Py")
'โปรแกรมจะมองหา Python.exe Local Python ก่อน ถ้าหาไม่เจอ จะไปหาที่ global Python ซึ่งได้กำหนดเส้นทางไดเรคทอรี่Tools-Configure Paths ก่อนหน้า
Dim opt As PyOptions = Py.CreateOptions("Python/python/python.exe")
'แต่กรณีไม่ได้กำหนดเส้นทางไดเรคทอรี่Tools-Configure Paths และ ไม่สามารถค้นหา Local Python เจอ เราต้องเขียนคำสั่งต่อไปนี้แทน
'Dim opt As PyOptions = Py.CreateOptions(File.Combine("", "C:\Python\python313\python.exe")) '<-- ถ้าเราไม่ใช้คำสั่งนี้จะ Error เกิดขึ้น
Py.Start(opt)
Wait For Py_Connected (Success As Boolean)
If Success = False Then
LogError("Failed to start Python process.")
Return
End If
#End Region
End If
If IsUsed("PyBridge" ) then
Private Sub B4XPage_Background
Py.KillProcess
End Sub
End If
If IsUsed("PyBridge" ) then
Private Sub Py_Disconnected
Log("PyBridge disconnected")
End Sub
End If
Last edited: