B4J Tutorial [PyBridge] Tips to make life easier

1, Download VSCode to edit the Python source files (you get hints etc)
2, Put the Python source code in files directory. (set external tool to VSCode for easy editing)
3, Run the code from File.DirAssets folder. Your B4J code will look much cleaner without the Code = $"..."$ lines.
B4X:
Dim res As PyWrapper = Py.RunCode("func1",Array(a,b),File.ReadString(File.DirAssets,"First_Python.py"))

Python code (in DirAssets):
def func1(a, b):
    print(f"a = {a}  {type(a)} , b = {b}  {type(b)}")
    if isinstance(a, int) and isinstance(b, int):
        return int(a + b)
    else:
        return f"Numbers were not integers"
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
Cuda and Tensorflow on Windows

This can be a mine field to get working. The latest versions do not run on Windows, they are designed for Linux.
You will need to be a bit of a detective to get the correct set up.

Get the version of Python you are using. (cmd prompt: Python --version)

Find out which version of CUDA your GPU is using. (use nvidia-smi in a cmd prompt window - this will tell you the version of drivers and CUDA you have)

Then find a cuda library that will work ( I use 11.8 even though I have CUDA 12.7 card).
Then find a tensorflow that works with the version of CUDA from previous step.

Check PyTorch webpage for which version you need for your Python and CUDA.
 
Top