AirtestProject / Poco

A cross-engine test automation framework based on UI inspection
http://airtest.netease.com/
Apache License 2.0
1.74k stars 315 forks source link

ImportError: numpy.core.multiarray failed to import #616

Closed romansvesh closed 2 months ago

romansvesh commented 2 months ago

Describe the bug A clear and concise description of what the bug is. Or paste traceback below.

/Users/me/Projects/mobile/temp4/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py --mode=client --host=127.0.0.1 --port=59778 
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/Users/me/Projects/mobile'])
PyDev console: starting.
Python 3.10.9 (main, Dec 19 2022, 10:18:00) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin

from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco()

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last):  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 570, in <module>
    pydevconsole.start_client(host, port)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 498, in start_client
    process_exec_queue(interpreter)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 287, in process_exec_queue
    interpreter.add_exec(code_fragment)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_code_executor.py", line 109, in add_exec
    more, exception_occurred = self.do_add_exec(code_fragment)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 93, in do_add_exec
    command.run()
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_console_types.py", line 35, in run
    self.more = self.interpreter.runsource(text, '<input>', symbol)
  File "/Users/me/.pyenv/versions/3.10.9/lib/python3.10/code.py", line 74, in runsource
    self.runcode(code)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/__init__.py", line 3, in <module>
    from .pocofw import Poco
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/pocofw.py", line 11, in <module>
    from .agent import PocoAgent
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/agent.py", line 3, in <module>
    from poco.utils.airtest import AirtestInput
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/utils/airtest/__init__.py", line 2, in <module>
    from .input import AirtestInput
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/utils/airtest/input.py", line 5, in <module>
    from airtest.core.api import device as current_device
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/core/api.py", line 8, in <module>
    from airtest.core.cv import Template, loop_find, try_log_screen
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/core/cv.py", line 13, in <module>
    from airtest import aircv
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/aircv/__init__.py", line 1, in <module>
    from .aircv import *  # noqa
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/aircv/aircv.py", line 5, in <module>
    import cv2
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/Users/me/.pyenv/versions/3.10.9/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/__init__.py", line 3, in <module>
    from .pocofw import Poco
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/pocofw.py", line 11, in <module>
    from .agent import PocoAgent
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/agent.py", line 3, in <module>
    from poco.utils.airtest import AirtestInput
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/utils/airtest/__init__.py", line 2, in <module>
    from .input import AirtestInput
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/poco/utils/airtest/input.py", line 5, in <module>
    from airtest.core.api import device as current_device
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/core/api.py", line 8, in <module>
    from airtest.core.cv import Template, loop_find, try_log_screen
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/core/cv.py", line 13, in <module>
    from airtest import aircv
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/aircv/__init__.py", line 1, in <module>
    from .aircv import *  # noqa
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/airtest/aircv/aircv.py", line 5, in <module>
    import cv2
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/me/Projects/mobile/temp4/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/Users/me/.pyenv/versions/3.10.9/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: numpy.core.multiarray failed to import

To Reproduce Steps to reproduce the behaviour:

  1. launch android emulator
  2. pip install pocoui==1.0.94
  3. in python 3.10.9 session:
    
    from poco.drivers.android.uiautomation import AndroidUiautomationPoco

poco = AndroidUiautomationPoco()



**Expected behaviour**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**python version:** `python3.10.9`

**poco version:** `1.0.94`
> You can get poco version via `pip freeze` command.

**Smartphone:**
 - Device: android emulator API 30
 - OS: Android 11

** Desktop:**
- OS: MacOS Sonoma 14.5

**Additional context**
Add any other context about the problem here.
[temp_requirements.txt](https://github.com/user-attachments/files/16140771/temp_requirements.txt)
TsingShui commented 2 months ago

Because the cv2 used by poco dependent numpy version is 1. X, so you need to downgrade the numpy version. It is recommended that you create a virtual environment in which you specify the version of numpy.

romansvesh commented 2 months ago

@TsingShui I just understood that pocoui have it's own dependency from airtest. Now pocoui depends on airtest==1.2.5. So I shouldn't have to use airtest==1.3.4 in the same project. Thank you so much!