# 调用MindSpore内部函数时的语法错误TypeError: 'module' object is not callable

1系统环境

硬件环境\(Ascend/GPU/CPU\): Ascend/GPU/CPU

MindSpore版本: 不限

执行模式（动态图）:不限

Python版本: Python=3.7.5

操作系统平台: 不限

**2 报错信息**

2.1 问题描述

代码调用函数时，语法错误。

2.2 报错信息

```
/root/miniconda3/envs/bin/python /mnt/d/06_project/trouble-shooter/tests/proposer/master/test_front_initializer.py 
Traceback (most recent call last):
  File "/mnt/d/06_project/trouble-shooter/tests/proposer/master/test_front_initializer.py", line 6, in 
    tensor1 = initializer(data, [1, 2, 3], mindspore.float32)
TypeError: 'module' object is not callable
```

2.3 脚本代码

```
import numpy as np
import mindspore
from mindspore import Tensor
from mindspore.common import initializer

data = Tensor(np.zeros([1, 2, 3]), mindspore.float32)
tensor1 = initializer(data, [1, 2, 3], mindspore.float32)
```

**3 根因分析**

1.根据报错看出可能是方法引用的不对，首先看看包的位置在哪里呢

![](figures/03-120.png)

2.在包的安装位置中找到函数的定义的地方

```
grep -irn "def initializer" /home/archiconda3/envs/wys_op/lib/python3.7/site-packages
```

![](figures/04-121.png)

3.至此，我们找到函数的定义地方以及官网代码，至此我们的bug也解决了

![](figures/05-122.png)

**4 解决方案**

```
import numpy as np 
import mindspore 
from mindspore import Tensor 
from mindspore.common.initializer import initializer 

data = Tensor(np.zeros([1, 2, 3]), mindspore.float32) 
tensor1 = initializer(data, [1, 2, 3], mindspore.float32) 

print(tensor1) 
```

