numba cannot be imported and numba functions are disabled. Probably the execution is slow.
问题描述
运行代码会出现警告信息
numba cannot be imported and numba functions are disabled.
Probably the execution is slow.
Please install numba to gain a massive speedup.
(or if you prefer slow execution, set the flag numba=False to avoid this warning!)
即使把numba的import注释掉也还是会有这个警告、卸载numba也还是有,安装之后import还有警告。
python 3.10.11 numba-0.58.1 numpy-1.26.3 pandapower-2.13.1
复现步骤
上述环境运行以下代码
"""
https://discourse.jupyter.org/t/numba-module-cannot-be-imported-properly/19353
numba cannot be imported and numba functions are disabled.
Probably the execution is slow.
Please install numba to gain a massive speedup.
(or if you prefer slow execution, set the flag numba=False to avoid this warning!)
"""
import pandapower as pp
import numba
net = pp.create_empty_network()
b1 = pp.create_bus(net, vn_kv=20.)
b2 = pp.create_bus(net, vn_kv=20.)
pp.create_line(net, from_bus=b1, to_bus=b2, length_km=2.5, std_type="NAYY 4x50 SE")
pp.create_ext_grid(net, bus=b1)
pp.create_load(net, bus=b2, p_mw=1.)
pp.runpp(net) # 警告诞生处
排查过程
- 单纯使用numpy和pandapower不会有numba警告,为了测试这个,可以用以下代码证明
import numpy as np
import pandapower as pp
import pandapower.networks as networks
from numpy.linalg import matrix_power
from pandapower import runpp
np.random.seed(42)
np.ones(5)
# Define a 2x2 matrix
A = np.array([[2, 3], [4, 5]])
# Define the power of the matrix (in this case, A^2)
A_power_2 = matrix_power(A, 2)
print("Original matrix A:")
print(A)
print("\nMatrix A raised to the power of 2:")
print(A_power_2)
# create empty net
net = pp.create_empty_network()
# create buses
b1 = pp.create_bus(net, vn_kv=20., name="Bus 1")
b2 = pp.create_bus(net, vn_kv=.4, name="Bus 2")
b3 = pp.create_bus(net, vn_kv=.4, name="Bus 3")
# create bus elements
pp.create_ext_grid(net, bus=b1, vm_pu=1.02, name="Grid Connection")
pp.create_load(net, bus=b3, p_kw=100, p_mw=80, q_kvar=50, name="Load")
# create branch elements
tid = pp.create_transformer(net, hv_bus=b1, lv_bus=b2, std_type="0.4 MVA 20/0.4 kV", name="Trafo")
pp.create_line(net, from_bus=b2, to_bus=b3, length_km=.1, name="Line", std_type="NAYY 4x50 SE")
# Load a pre-defined power grid network
net = networks.case33bw()# io_utils.py:509: FutureWarning
print("Loaded network data:")
print(net)
- 版本兼容性问题
尝试安装 numbda 0.58.1 后取消注释还是会报警告,确认可以import;尝试 numba-0.58.0 numpy-1.25.2 后也是报警告;numba-0.57.0 numpy-1.24.4 也报警告;numba-0.56.0 numpy-1.22.4 则不报警告
结论
版本兼任问题,pandapower-2.13.1 和numba的0.57-0.58.1有,前者issue注意到了后者version接口变更了,待后续修复,现在可先用 numba-0.56.0