Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: invalid syntax #571

Closed
Malkhafaji95 opened this issue Oct 24, 2020 · 4 comments
Closed

SyntaxError: invalid syntax #571

Malkhafaji95 opened this issue Oct 24, 2020 · 4 comments
Labels

Comments

@Malkhafaji95
Copy link

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
Copy link
Member

hx2A commented Oct 24, 2020

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
Copy link
Author

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
Copy link
Member

  • 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.

@github-actions
Copy link

👋 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants