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

AttributeError: 'HTMLParser' object has no attribute 'unescape' #416

Closed
Spidey-code opened this issue Dec 27, 2020 · 18 comments
Closed

AttributeError: 'HTMLParser' object has no attribute 'unescape' #416

Spidey-code opened this issue Dec 27, 2020 · 18 comments
Labels

Comments

@Spidey-code
Copy link

Failed to install et_xmlfile from https://files.pythonhosted.org/packages/22/28/a99c42aea746e18382ad9fb36f64c1c1f04216f41797f2f0fa567da11388/et_xmlfile-1.0.1.tar.gz.
this error pops up when i run my android file though its perfectly run on python file but when i call it from android its show up this error

This is my build,gradle(app) file
`plugins {
id 'com.android.application'
id 'com.chaquo.python'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
    python{
        pip{
            install "numpy"
            install "pandas"
            install "xlrd"
            install 'openpyxl'
            install 'et_xmlfile'
        }
    }
    applicationId "com.example.androidwithpython"

    //give source folder to python
    sourceSets{
        main{
            python{
                srcDirs = ["src/main/python"]
            }
        }
    }
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    ndk {
        abiFilters "armeabi-v7a", "x86"
    }

    //here give path to file python.exe
    python{
        buildPython "C:/Python/python.exe"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility sourceCompatibility1
    targetCompatibility targetCompatibility1
}

}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}`

@mhsmith mhsmith changed the title cant read xml file in android cant install et_xmlfile in android Dec 27, 2020
@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

et_xmlfile works fine for me. Please post the full build log (click the 'Build: failed' caption to the left of the message).

Also, which version of Chaquopy are you using (com.chaquo.python:gradle in your top-level build.gradle file)?

@Spidey-code
Copy link
Author

Spidey-code commented Dec 27, 2020

"com.chaquo.python:gradle:9.0.0" this is the version im using and i also checked the min sdk version 16 ,python version 3.9, gradle version 4.1.1
com.chaquo.python.PyException: ModuleNotFoundError: No module named 'et_xmlfile' this is the main error
below this is build log

E/AndroidRuntime:** FATAL EXCEPTION: main
    Process: com.example.androidwithpython, PID: 12319
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidwithpython/com.example.androidwithpython.MainActivity}: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'et_xmlfile'
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'et_xmlfile'
        at <python>.java.chaquopy.import_override(import.pxi:20)
        at <python>.java.chaquopy.import_override(import.pxi:60)
        at <python>.LocalDataset.<module>(LocalDataset.py:4)
        at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
        at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:783)
        at <python>.java.android.importer.exec_module(importer.py:507)
        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_getModule(chaquopy_java.pyx:156)
        at com.chaquo.python.Python.getModule(Native Method)
        at com.example.androidwithpython.MainActivity.onCreate(MainActivity.java:36)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

The build log please, not the runtime error. To display the full log, click the "Build: failed" caption to the left of "Failed to install et_xmlfile ...".

@Spidey-code
Copy link
Author

Spidey-code commented Dec 27, 2020

Executing tasks: [:app:assembleDebug] in project D:\Raju\Android\AndroidWithPython

> Configure project :app
Warning: This version of Chaquopy has not been tested with Android Gradle plugin versions beyond 4.1.0. If you experience problems, please edit the version of com.android.tools.build:gradle in your top-level build.gradle file. See https://chaquo.com/chaquopy/doc/current/versions.html.

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:extractPythonBuildPackages UP-TO-DATE

> Task :app:generateDebugPythonRequirements
Chaquopy: Installing for armeabi-v7a
Looking in indexes: https://pypi.org/simple, https://chaquo.com/pypi-7.0
Collecting numpy
  Using version 1.17.4 (newest version is 1.19.4, but Chaquopy prefers native wheels)
  Using cached https://chaquo.com/pypi-7.0/numpy/numpy-1.17.4-3-cp38-cp38-android_16_armeabi_v7a.whl
Collecting pandas
  Using version 0.25.3 (newest version is 1.2.0, but Chaquopy prefers native wheels)
  Using cached https://chaquo.com/pypi-7.0/pandas/pandas-0.25.3-1-cp38-cp38-android_16_armeabi_v7a.whl
Collecting xlrd
  Using cached https://files.pythonhosted.org/packages/a6/0c/c2a72d51fe56e08a08acc85d13013558a2d793028ae7385448a6ccdfae64/xlrd-2.0.1-py2.py3-none-any.whl
Collecting et_xmlfile
  Using cached https://files.pythonhosted.org/packages/22/28/a99c42aea746e18382ad9fb36f64c1c1f04216f41797f2f0fa567da11388/et_xmlfile-1.0.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
      File "<frozen zipimport>", line 259, in load_module
      File "D:\Raju\Android\AndroidWithPython\app\build\generated\python\bp.zip\setuptools\__init__.py", line 14, in <module>
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
    Command "python setup.py egg_info" failed with error code 1 in C:\Users\sujeet\AppData\Local\Temp\pip-install-s4imb6yn\et-xmlfile\
      File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
      File "<frozen zipimport>", line 259, in load_module
      File "D:\Raju\Android\AndroidWithPython\app\build\generated\python\bp.zip\setuptools\dist.py", line 24, in <module>
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
      File "<frozen zipimport>", line 259, in load_module
      File "D:\Raju\Android\AndroidWithPython\app\build\generated\python\bp.zip\setuptools\depends.py", line 7, in <module>
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
      File "<frozen zipimport>", line 259, in load_module
      File "D:\Raju\Android\AndroidWithPython\app\build\generated\python\bp.zip\setuptools\py33compat.py", line 54, in <module>
    AttributeError: 'HTMLParser' object has no attribute 'unescape'
    
    ----------------------------------------
ERROR: Failed to install et_xmlfile from https://files.pythonhosted.org/packages/22/28/a99c42aea746e18382ad9fb36f64c1c1f04216f41797f2f0fa567da11388/et_xmlfile-1.0.1.tar.gz.
For assistance, please raise an issue at https://github.com/chaquo/chaquopy/issues.
Chaquopy: Exit status 1

@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

Thanks, it looks like we have a compatibility problem with Python 3.9. We'll fix this in the next version of Chaquopy.

Meanwhile, please install Python 3.8.7 from here. If you install it with the default settings, you should just be able to remove the buildPython line from your build.gradle file and the build will use it automatically.

@mhsmith mhsmith added bug and removed packages labels Dec 27, 2020
@Spidey-code
Copy link
Author

Spidey-code commented Dec 27, 2020

so i have remove this code from buld file
python{ pip{ install "numpy" install "pandas" install 'xlrd' install 'et_xmlfile' } }

and Thanks for the help . It was really annoying to not solve the bug really great thanks for the help

@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

You don't need to remove the pip block, only the buildPython line.

@Spidey-code
Copy link
Author

This code
python{ buildPython "C:/Python/python.exe" }

@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

Yes, if you install Python 3.8 with the default settings then you can just remove that line. Or if that doesn't work, try editing the line to point at the Python 3.8 executable.

@Spidey-code
Copy link
Author

OK I'll try this method

@Spidey-code
Copy link
Author

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidwithpython/com.example.androidwithpython.MainActivity}: com.chaquo.python.PyException: FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Raju\\Python\\project\\datasets\\soilexcel.xlsx'
After running with the python 3.8 its shows me this error though i have file on that loaction

@Spidey-code Spidey-code changed the title cant install et_xmlfile in android com.chaquo.python.PyException: FileNotFoundError: [Errno 2] No such file or directory: Dec 27, 2020
@mhsmith mhsmith changed the title com.chaquo.python.PyException: FileNotFoundError: [Errno 2] No such file or directory: AttributeError: 'HTMLParser' object has no attribute 'unescape' Dec 27, 2020
@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

Even if it's running on the emulator, an Android app still has no access to files on your development machine. They're effectively two separate devices.

However, any data file in your Python source directory will be copied into your APK and extracted onto the Android device. You can then access it using a path relative to __file__, as shown here.

Please create separate issues for separate problems.

@Spidey-code
Copy link
Author

Spidey-code commented Dec 27, 2020

sorry for that !! do this code will work for excel file also with .xlsx format and I have to use pandas library for further code do this code with take dataframe objects too

@mhsmith
Copy link
Member

mhsmith commented Dec 27, 2020

The code for finding a file will work with any file. What you do with the file once you've found it is up to you.

By the way, could you please not copy my avatar, it makes the conversation look confusing.

@Spidey-code
Copy link
Author

ok sorry I just find it look good ! n thanks for the code n solving my queries . can I have the Twitter handle of yours I really like to see a developer to be connected

@mhsmith
Copy link
Member

mhsmith commented Dec 28, 2020

https://twitter.com/chaquopy

Let's leave the issue open until the problem is fixed, because it looks like it breaks all installation of sdists with Python 3.9.

@mhsmith mhsmith reopened this Dec 28, 2020
@Spidey-code
Copy link
Author

Spidey-code commented Dec 28, 2020

Thanks for the help. Your are damn great . i was stuck with this for days and great technology to integrate android with python.
Hail Chaquopy !!

@mhsmith
Copy link
Member

mhsmith commented Jan 3, 2021

This issue is fixed in Chaquopy 9.1.0. To upgrade, edit your app's top-level build.gradle file and change the version number of com.chaquo.python:gradle.

If for some reason you don't want to upgrade Chaquopy, you can work around the problem by using Python 3.8 as discussed above.

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

3 participants
@mhsmith @Spidey-code and others