anaconda和Spyder中的包加载错误 [英] Package load error in anaconda and Spyder

查看:718
本文介绍了anaconda和Spyder中的包加载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Anaconda 4.3.1中的Spyder 3.1.4中编辑了三个python 2.7文件

 (1)。 TestClass.py:只需将
import numpy定义为np
class TestClass:
def getArray(self):
return np.zeros((3,4));
(2)。来自TestClass import *的a1.py
;
tt = TestClass();

(3)。 a2.py
#just一个空的python文件

当我runfilea1。 py在Spyder中,创建了一个TestClass实例tt,我在Spyder的IPython控制台中运行以下代码:

  tt.getArray( )
Out [9]:
数组([[0.,0.,0.,0。],
[0.,0.,0.,0。],
[0.,0.,0.,0。]])

它正常工作,但是在我在Spider中运行文件a2.py(一个空文件)后,我在Spyder的IPython控制台中重新运行tt.getArray()时,出现错误:



tt.getArray()
回溯(最近一次调用最后一次):



文件,第1行,
tt.getArray( )



文件TestClass.py,第6行,在getArray中
返回np.zeros((3,4));



AttributeError:'NoneType'对象没有属性'zeros'
numpy变得缺失,根据我的经验,Spyder中的任何runfile操作符都会导致缺少numpy。任何关于tt的代码都不能写入a2.py,因为运行新文件时缺少tt alread导入的包。这是一个错误吗?或Spyder,Ipython需要进一步配置或设置参数?或者spyder中的runfile命令需要额外的参数吗?



我已经厌倦了这个错误,请告诉我哪里出错了。

解决方案

因为Spyder有用户模块重新加载(UMR)属性,我们运行runfile函数运行一个脚本,Spyder将重新加载所有用户创建的模块。 / p>

在我的环境中,Spyder重新加载TestClass但没有重新加载numpy,并且卸载了TestClass bounded numpy,因此runfile会导致用户模块无效。




工具 - >首选项 - > Python解释器
我们可以关闭UMR


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.

解决方案

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

这篇关于anaconda和Spyder中的包加载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆