PyDev:未解决的导入 [英] PyDev: Unresolved import

查看:85
本文介绍了PyDev:未解决的导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中使用PyDev,并为我的Python项目提供了一个自定义源路径: src/main/python /.该路径已添加到PythonPath.

I use PyDev in Eclipse and have a custom source path for my Python project: src/main/python/. The path is added to the PythonPath.

现在,我想使用库pyMIR: https://github.com/jsawruk/pymir,它没有任何安装脚本.因此,我下载了它,并将其作为Pydev软件包包含在我的项目中,pyMIR的完整路径为: src/main/python/music/pymir .

Now, i want to use the library pyMIR: https://github.com/jsawruk/pymir, which doesn't has any install script. So I downloaded it and and included it direclty into my project as a Pydev package, the complete path to the pyMIR is: src/main/python/music/pymir.

在音乐包( src/main/python/music )中,现在我想使用该库并通过以下方式导入它:from pymir import AudioFile.没有出现错误,因此找到了AudioFile类.

In the music package (src/main/python/music), now i want to use the library and import it via: from pymir import AudioFile. There appears no error, so class AudioFile is found.

然后,我想通过以下方式读取音频文件:AudioFile.open(path),并且出现错误来自导入的未定义变量:打开".但是,当我运行脚本时,它可以正常工作,不会发生任何错误.

Afterward, I want to read an audio file via: AudioFile.open(path) and there i get the error "Undefined variable from import: open". But when I run the script, it works, no error occurs.

此外,当我查看pyMIR软件包时,还存在未解决的导入错误.例如:类AudioFile中的from pymir import Frame会产生错误:"Unresolved import:Frame",当我将其更改为from music.pymir import Frame时,该错误消失了,但是当它运行时我得到了一个错误:"type object'Frame'没有属性框架"".

Furthermore, when I look in the pyMIR package, there are also unresolved import errors. For example: from pymir import Frame in the class AudioFile produces the error: "Unresolved import: Frame", when I change it to from music.pymir import Frame, the error disappears, but then I get an error when it runs: "type object 'Frame' has no attribute 'Frame'".

  1. 我需要更改的内容,另一项导入或如何包含Pydev软件包?

  1. What I have to change, another import or how to include a Pydev package?

当我使用标准路径"src"创建新项目时,不会出现"unresolved impor"错误.与 src/main/python 的区别在哪里?因为我将源文件夹的路径更改为 src/main/python .

When I make a new project with a standard path "src", then no "unresolved impor" errors appear. Where is the difference to src/main/python? Because I changed the path of source folders to src/main/python.

谢谢.

推荐答案

我尝试下载并安装pymir软件包.有一个适合我的项目结构:

I tried to download and install the pymir package. There is one project structure that works for me:

project/music/
project/music/pymir/
project/music/pymir/AudioFile
project/music/pymir/...
project/music/audio_files/01.wav
project/music/test.py

test.py:

import numpy
from pymir import AudioFile
filename = "audio_files/01.wav"
print "Opening File: " + filename
audiofile = AudioFile.open(filename)
frames = audiofile.frames(2048, numpy.hamming)
print len(frames)

如果我将'test.py'从'music'包中移出,我还没有找到一种使之工作的方法.在我看来,项目结构之所以敏感且棘手,是因为pymir软件包的结构不够好.例如,作者将模块名称设置为"Frame.py",并且在模块内部将一个类命名为"Frame".然后在"__init__.py"中,代码​​类似于从框架导入框架".在"AudioFile.py"中,代码​​是来自pymir import Frame".我真的认为当前pymir的命名和结构很混乱.建议您仔细使用此程序包

If I moved 'test.py' out from 'music' package, I haven't found a way to make it work. The reason why the project structure is sensitive and tricky is, in my opinion, the pymir package is not well structured. E.g., the author set module name as "Frame.py" and inside the module a class is named "Frame". Then in "__init__.py", codes are like "from Frame import Frame". And in "AudioFile.py", codes are "from pymir import Frame". I really think the naming and structure of the current pymir is messy. Suggest you use this package carefully

这篇关于PyDev:未解决的导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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