首页 > 解决方案 > 无法从“asyncio”导入名称“get_running_loop”

问题描述

有一个简单的脚本

# -*- coding: utf-8 -*-
import xlwings as xw
import pandas as pd
    
wb = xw.Book('Excel_Python-1.xlsx') 
data_excel = wb.sheets['Данные'] 
data_pd = data_excel.range('A1:C4').options(pd.DataFrame, header = 1, index = False).value 
print(data_pd)

启动时出错:无法从“asyncio”导入名称“get_running_loop”

检查 'get_running_loop' 方法是否在来自 'asyncio' 的 events.py 模块中。可能是什么问题呢?

"C:\Program Files\Python_370\python.exe" O:/___Python/__Examples/Excel/excel-1.py
Traceback (most recent call last):
  File "O:/___Python/__Examples/Excel/excel-1.py", line 2, in <module>
    import xlwings as xw
  File "C:\Program Files\Python_370\lib\site-packages\xlwings\__init__.py", line 38, in <module>
    from .udfs import xlfunc as func, xlsub as sub, xlret as ret, xlarg as arg, get_udf_module, import_udfs
  File "C:\Program Files\Python_370\lib\site-packages\xlwings\udfs.py", line 4, in <module>
    from asyncio import get_running_loop
ImportError: cannot import name 'get_running_loop' from 'asyncio' (C:\Program Files\Python_370\lib\asyncio\__init__.py)

我以交互方式运行脚本。结果如下:

C:\Windows\system32>python
Python 3.7.0a1 (v3.7.0a1:8f51bb4, Sep 19 2017, 19:32:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # -*- coding: utf-8 -*-
... import xlwings as xw
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Program Files\Python_370\lib\site-packages\xlwings\__init__.py", line 38, in <module>
    from .udfs import xlfunc as func, xlsub as sub, xlret as ret, xlarg as arg, get_udf_module, import_udfs
  File "C:\Program Files\Python_370\lib\site-packages\xlwings\udfs.py", line 4, in <module>
    from asyncio import get_running_loop
ImportError: cannot import name 'get_running_loop' from 'asyncio' (C:\Program Files\Python_370\lib\asyncio\__init__.py)
>>> import pandas as pd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python_370\lib\site-packages\pandas\__init__.py", line 17, in <module>
    "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.7 from "C:\Program Files\Python_370\python.exe"
  * The NumPy version is: "1.20.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

>>>
>>> wb = xw.Book('Excel_Python-1.xlsx')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'xw' is not defined
>>> data_excel = wb.sheets['Данные']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'wb' is not defined
>>> data_pd = data_excel.range('A1:C4').options(
...     pd.DataFrame, header = 1, index = False).value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'data_excel' is not defined
>>> print(data_pd)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'data_pd' is not defined

但是从中得出什么结论-我不知道

标签: pythonpandasxlwings

解决方案


推荐阅读