【问题标题】:Import where subfolder is same as outer folder导入子文件夹与外部文件夹相同的位置
【发布时间】:2011-06-14 22:05:23
【问题描述】:

我想使用这个名为 Music21 的框架。

在 shell 中一切正常。例如命令:

from music21 import corpus

完美运行。在 IDE 中出现导入错误。

music21 路径是:

>>> music21.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/music21/__init__.pyc'

我把这条路径放在 IDE 中:

编辑:命令:

导入音乐21 打印目录(music21)

在外壳中给我:

['DefinedContexts','DefinedContextsException','ElementException','ElementWrapper','GroupException','Groups','JSONSerializer','JSONSerializerException','Music21Exception','Music21Object','Music21ObjectException','Test ', 'TestMock', 'VERSION', 'VERSION_STR', 'WEAKREF_ACTIVE', 'all', 'builtins', 'doc' , '文件', '名称', '', '路径', 'abc', ' abj', '分析', 'articulations', 'bar', 'base', 'beam', 'chord', 'chordTables', 'clef', 'codecs', 'common', 'composition', 'configure' , 'converter', 'copy', 'corpus', 'counterpoint', 'defaults', 'demos', 'derivation', 'doc', 'doctest', 'duration', 'dynamics', '社论', ' environLocal'、'environment'、'expressions'、'figuredBass'、'graph'、'humdrum'、'inspect'、'instrument'、'interval'、'intervalNetwork'、'json'、'key'、'layout' , '百合', 'mainTest', 'matplotlib', 'medren', '元数据', 'meter', 'midi', 'musedata', ' musicxml','note','numpy','parse','pitch','ratio','repeat','roman','romanText','scale','serial','sieve','spanner' , 'stream', 'sys', 'tempo', 'test', 'text', 'tie', 'tinyNotation', 'trecento', 'types', 'unittest', 'uuid', 'voiceLeading', ' xmlnode']

在 IDE 中:

['author', 'builtins', 'date', 'doc', '文件'、'名称'、''、'music21']

【问题讨论】:

  • netBeans 6.9.1。我用的是雪豹。

标签: python music21


【解决方案1】:

路径应该是正确的 python 可执行文件或其文件夹。

【讨论】:

  • 嗨,我做了你说的 - 不工作。最可怕的部分是“import music21”行有效,但在其中找不到语料库..
【解决方案2】:

在 Python 中,每个包含 __init__.py 的目录都是一个包。 sys.path 包含 Python 搜索包的目录,所以你应该使用

'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/'

能够从该目录导入音乐和其他包。

【讨论】:

    【解决方案3】:

    您似乎已将 music21 安装在一个也称为 music21 的文件夹中,而后者(外部)文件夹位于您的 IDE 路径中,但内部文件夹在其他情况下位于您的路径中。因此,当您在 IDE 中键入“import music21”时,您已经导入了外部文件夹,您需要键入这个晦涩的命令“from music21 import music21”才能访问实际的工具包。

    --

    如果“corpus”是您看到的唯一问题,我猜您安装了两个不同版本的 music21,其中一个是来自 http://code.google.com/p/music21/downloads/list 的工具包的“noCorpus”版本

    我们制作 noCorpus 版本的唯一原因是其中的某些文件不是全球范围内的免费软件(它们都完全在美国获得许可)和 Linux Dist。想用它打包music21,但不能包含一些语料库文件。除非您的磁盘空间真的很低或维护墨西哥的生命版权法+100 等,否则您可能不需要 noCorpus 版本。

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      相关资源
      最近更新 更多