pyjnius
pyjnius copied to clipboard
SyntaxError: invalid syntax
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
File "/snap/pycharm-community/214/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 107, in
Thanks in advance
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.
I ran the code using the terminal and i got this error:
Traceback (most recent call last):
File "java.py", line 2, in
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
- your syntax error is from using python2 print syntax, rather than python3, (python2 needs parenthesis), we need to update the example code indeed, but i would assume a python dev would know that.
- your ide probably defines a virtualenv, so doesn't see globaly installed packages.
- this code won't work on desktop, it won't be able to find the relevant java classes, and to run them, as these are android-specific, to test this code you need to package your code for android using p4a/buildozer.
this place is not for user support, but for bugs.
👋 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.