Package load error in anaconda and Spyder

依然范特西╮ 提交于 2019-12-24 01:54:54

问题


I have three python 2.7 files edit in Spyder 3.1.4 in Anaconda 4.3.1

(1). TestClass.py :Just define a class 
import numpy as np
class TestClass:
    def getArray(self):
        return np.zeros((3,4));
(2). a1.py
from TestClass import *;
tt=TestClass();

(3). a2.py
#just a empty python file

When I "runfile" "a1.py" in Spyder, a TestClass instance tt was created, and I run following code in Spyder's IPython console:

tt.getArray()
Out[9]: 
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])

It works correctly, but after I runfile a2.py (a empty file) in Spider, and I re-run "tt.getArray()" in Spyder's IPython console, the error occours:

tt.getArray() Traceback (most recent call last):

File "", line 1, in tt.getArray()

File "TestClass.py", line 6, in getArray return np.zeros((3,4));

AttributeError: 'NoneType' object has no attribute 'zeros' the numpy became missing, in my experience any "runfile" operator in Spyder will lead to missing numpy. Any code about "tt" can't not write in a2.py because tt alread imported package are missing when run a new file. Is this a bug ? Or Spyder, Ipython need further configure or set parameter? Or "runfile" command in spyder need additional paramter?

I have go mad with this error, please tell me where I went wrong.


回答1:


Because Spyder have "User Module Reloade (UMR)" Property, we us "runfile" function run a script, Spyder will reload all the user created modules.

In my environment, Spyder reload TestClass but not reload numpy, and TestClass bounded numpy was unloaded, so "runfile" can cause users modules invalid.

In Tools->Preferences->Python Interpreter we can close UMR



来源:https://stackoverflow.com/questions/44061754/package-load-error-in-anaconda-and-spyder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!