How to use enum from Python3 and not enum from PyPI -- issue during the Android VTS setup on Windows?

1.7k Views Asked by At

I am trying to setup AOSP VTS test on Windows. When installing, there is a pip_requirements.txt which tries to download the enum package which later will be installed during the test execution. When the test case is being run, there is an enum related issue that is causing the vts-run to fail. The error that comes during the test run is as shown below.

 ..\AppData\Local\Temp\pip-install-zp3vtjdn\enum\setup.py", line 24, in <module>
            version = main_module.__version__
        AttributeError: module 'enum' has no attribute '__version__'

Ref to the VTS test execution steps: https://codelabs.developers.google.com/codelabs/android-vts/index.html?index=..%2F..index#1

pip download -d %VTS_PYPI_PATH% -r pip_requirements.txt

NOTE: Even if the pip_requirements.txt is ignored, looks like the vts-tradefed application is going to install the enum and few other modules, which will still cause this issue. The application refers to a set of .jar files, whose source code confirms this. Also, to verify I tried running vts without downloading the modules using the above steps. But still got the same enum related error.

The property of the enum.__file__ is as shown below:

>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> print(enum.__file__)
C:\Python37\lib\enum.py

After some analysis, I found that the enum package that is being downloaded by the pip is downloading the following "https://pypi.org/project/enum/". This package has a enum.py too which is probably the reason for causing the attribute error:

AttributeError: module 'enum' has no attribute '__version__'

The PyPI page link mentions that:

Superseded by Python standard library.

Python 3 now has in its standard library an enum implementation (also available for older Python versions as the third-party enum34 distribution) that supersedes this library.

My understanding is: since the Python3 enum package superseeds the PyPI enum package, the Python3 enum package should be used instead of the PyPI enum package right?

Is my understanding right? If so, then how to achieve that? i.e. when pip tries to download/install the enum package, how to redirect it to use the Python3 enum pacakage and not use the enum package by PyPI?

Thanks in advance!!

1

There are 1 best solutions below

0
On

The Python 3 Enum is not a drop-in replacement for the PyPI enum -- they have different APIs. If the package being installed really needs the PyPI version then the stdlib version won't work.