未定义的来自导入的变量

未定义的来自导入的变量

本文介绍了“未定义的来自导入的变量”在eclipse pydev中导入numpy时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我从numpy导入一个模块时,我得到Eclipse 3.7.2 PyDev 2.7.1在Linux Mint Maya(Cinnamon)上的未定义变量导入错误。问题只在导入numpy时出现;其他模块工作正常。



信息:numpy是针对英特尔MKL库编译的。 Python 2.7.3 [GCC 4.6.3]



示例:

  import numpy as np 

a = np.array([1,2])

PyDev编辑器中的错误消息:
从导入中获取未定义的变量:



我发现其他numpy子模块的类似错误。



代码在Eclipse或终端中正常运行。该问题仅存在于Eclipse-PyDev编辑器中。

解决方案

LD_LIBRARY_PATH 必须包含MKL库的路径。即使 LD_LIBRARY_PATH 设置正确,它必须在Eclipse的窗口>首选项>解释器 - Python下,在右侧的环境选项卡下显式指定。添加一个名为LD_LIBRARY_PATH的新变量,并粘贴 $ LD_LIBRARY_PATH 的内容。



一旦完成,错误如果将行添加到使用numpy对象的代码中,以便再次检查导入,则只会从代码中消失。


I get "Undefined variable from import" error in Eclipse 3.7.2 PyDev 2.7.1 on Linux Mint Maya (Cinnamon) whenever I import a module from numpy. The problem only arises when importing numpy; other modules work just fine.

Info: numpy is compiled against the Intel MKL libraries. Python 2.7.3 [GCC 4.6.3]

example:

import numpy as np

a = np.array([1, 2])

Error message in PyDev editor:"Undefined variable from import: array"

I get similar errors for other numpy submodules.

The code runs properly either within Eclipse or in a terminal. The problem is only present in the Eclipse-PyDev editor.

解决方案

The LD_LIBRARY_PATH has to contain paths to the MKL libraries. Even if LD_LIBRARY_PATH is set properly, it has to be explicitly specifed in Eclipse under Window > Preferences > Interpreter - Python, under the "Environment" tab on the right hand side. Add a new variable called "LD_LIBRARY_PATH" and paste the content of $LD_LIBRARY_PATH.

Once it is done, errors will only disappear from your code if a line is added to the code which uses a numpy object so that imports are checked again.

这篇关于“未定义的来自导入的变量”在eclipse pydev中导入numpy时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:43