kivy / pyjnius

Access Java classes from Python
https://pyjnius.readthedocs.org
MIT License
1.39k stars 254 forks source link

SyntaxError: invalid syntax #571

Closed Malkhafaji95 closed 10 months ago

Malkhafaji95 commented 3 years ago

I'm trying to test out the sample code provided on Github and I'm getting a syntax error. I have a feeling this might be a pathing issue but pyjnius is in the environment path.

the words jnius and autoclass are underlined in red. When i hover over it, it was " Unresolved reference 'jnius'"

Code:

from time import sleep from jnius import autoclass

Hardware = autoclass('org.renpy.android.Hardware') print 'DPI is', Hardware.getDPI()

Hardware.accelerometerEnable(True) for x in xrange(20): print Hardware.accelerometerReading() sleep(.1)


error:

Traceback (most recent call last): File "/snap/pycharm-community/214/plugins/python-ce/helpers/pydev/pydevd.py", line 39, in from _pydevd_bundle.pydevd_comm import CMD_SET_BREAK, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO, CMD_STEP_OVER, \ File "/snap/pycharm-community/214/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 107, in from _pydev_bundle import _pydev_completer File "/snap/pycharm-community/214/plugins/python-ce/helpers/pydev/_pydev_bundle/_pydev_completer.py", line 9, in import java.lang #@UnusedImport File "/home/malkhafa/PycharmProjects/pythonProject1/java.py", line 5 print 'DPI is', Hardware.getDPI() ^ SyntaxError: invalid syntax


Thanks in advance

hx2A commented 3 years ago

It looks like the path PyCharm is using points to an environment that does not have pyjnius installed. Either you didn't install it correctly or there is an issue with PyCharm. Most likely the later. Sometimes IDEs won't automatically find the Python environment you intend and you need to manually point it to the right one. I have this issue from time to time with my IDE. I don't use PyCharm so I can't help you with that part. Good luck.

Malkhafaji95 commented 3 years ago

I ran the code using the terminal and i got this error:

Traceback (most recent call last): File "java.py", line 2, in from jnius import autoclass ImportError: No module named jnius

the environmental paths are :

/home/malkhafa/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

and pyjnius us install at :

./.local/lib/python3.6/site-packages

tshirtman commented 3 years ago

this place is not for user support, but for bugs.

github-actions[bot] commented 10 months ago

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project. Let us know if this comment was made in error, and we'll be happy to reopen the issue.