oracle / graalpython

GraalPy – A high-performance embeddable Python 3 runtime for Java
https://www.graalvm.org/python/
Other
1.25k stars 111 forks source link

AttributeError: foreign object has no attribute 'valueOf' #410

Closed ahmednrana closed 4 months ago

ahmednrana commented 4 months ago

I am trying out python but whenever I try to access Java from it. It throws error.

import java
BigInteger = java.type("java.math.BigInteger")
myBigInt = BigInteger.valueOf(42)

It gives the following error

C:\tools\graalpy-24.0.1-windows-amd64\bin\python.exe C:\Dev\java\pythonProject1\hi.py --jvm --experimental-options --python.EmulateJython 
Traceback (most recent call last):
  File "C:\Dev\java\pythonProject1\hi.py", line 3, in <module>
    myBigInt = BigInteger.valueOf(42)
AttributeError: foreign object has no attribute 'valueOf'

I am using Pycharm.

msimacek commented 4 months ago

Hi @ahmednrana, you need to download the jvm standalone version. For windows that is graalpy-jvm-24.0.1-windows-amd64.zip from the release page

ahmednrana commented 4 months ago

Thanks. This ran the script. I have another question. Does pycharm / vscode works in autocompletion? Is there a way to use a debugger with it using these IDEs

msimacek commented 4 months ago

Yes, in PyCharm when you set up the project, you can select creating a new virtualenv and use the bin/python binary in the graalpy directory as the base interpreter. Then everything should just work, including the debugger. Although some things can be quite slow, especially the initial indexing. I believe vscode should work too, but I haven't tried it recently.

ahmednrana commented 4 months ago

I was unable to use it with pycharm. Debugger or the autocomplete when it invovolves java. Thanks