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

com.chaquo.python.PyException: AttributeError: module 'typing' has no attribute '_ClassVar' #849

Closed
karannair45 opened this issue Apr 10, 2023 · 3 comments

Comments

@karannair45
Copy link

karannair45 commented Apr 10, 2023

I am trying to implement the google api in chaquopy.

The following libraries in my python script are:

from google_auth_oauthlib.flow import Flow, InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
from google.auth.transport.requests import Request
from oauth2client.service_account import ServiceAccountCredentials
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

The stack trace is:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myloginapp, PID: 16480
    com.chaquo.python.PyException: AttributeError: module 'typing' has no attribute '_ClassVar'
        at <python>.dataclasses._is_classvar(dataclasses.py:550)
        at <python>.dataclasses._get_field(dataclasses.py:659)
        at <python>.dataclasses.<listcomp>(dataclasses.py:800)
        at <python>.dataclasses._process_class(dataclasses.py:800)
        at <python>.dataclasses.wrap(dataclasses.py:950)
        at <python>.dataclasses.dataclass(dataclasses.py:958)
        at <python>.pkg_resources.extern.packaging._tokenizer.<module>(_tokenizer.py:10)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.pkg_resources.extern.packaging._parser.<module>(_parser.py:10)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.pkg_resources.extern.packaging.requirements.<module>(requirements.py:8)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.pkg_resources.<module>(__init__.py:93)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.googleapiclient.model.<module>(model.py:30)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.googleapiclient.http.<module>(http.py:64)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.googleapiclient.discovery.<module>(discovery.py:68)
        at <python>.java.chaquopy.import_override(import.pxi:26)
        at <python>.googleFolderSelect.<module>(googleFolderSelect.py:7)
        at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
        at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:843)
        at <python>.java.android.importer.exec_module(.\java\android\importer.py:545)
        at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
        at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
        at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
        at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
        at <python>.importlib.import_module(__init__.py:127)
        at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModuleNative(chaquopy_java.pyx:154)
        at com.chaquo.python.Python.getModuleNative(Native Method)
        at com.chaquo.python.Python.getModule(Python.java:84)
        at com.example.myloginapp.SecondActivity$3.onClick(SecondActivity.java:105)
        at android.view.View.performClick(View.java:5653)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
        at android.view.View$PerformClick.run(View.java:22461)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6138)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
@mhsmith
Copy link
Member

mhsmith commented Apr 10, 2023

The first few Google results for this error indicate that it's caused by installing the backported dataclasses package, which is incompatible with Python 3.7 or newer:

You'll need to work out which of your pip requirements is pulling this package in, then update or remove it.

@karannair45
Copy link
Author

I get these errors from the following imports:

from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

In my Gradle, the versions of these python libraries that give the error are:

google-api-python-client==2.6.0
PyDrive==1.3.1
google-auth==1.35.0
google-drive==0.5.0
google-auth-httplib2==0.1.0

Would the solution to be changing the versions of these libraries? If I remove it then some of the functions in my code won't work.

@mhsmith
Copy link
Member

mhsmith commented Apr 10, 2023

Try removing your requirements one at a time, rebuilding your app, and looking at the build log, until dataclasses stops appearing in the log. Or if you have a lot more requirements than those you've shown, you can use a binary search.

Once you know which requirement depends on dataclasses, you should be able to upgrade it to a newer version that doesn't have that dependency.

@mhsmith mhsmith closed this as completed Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants