开发者

Import where subfolder is same as outer folder

I want to use this framework called Music21.

In the shell everything works fine. For example, the command:

from music21 import corpus

works perfectly. In the IDE there is an import error.

the music21 path is:

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

I put this path in the IDE:

Import where subfolder is same as outer folder

EDIT: the commands:

import music21 print dir(music21)

gives me in the shell:

开发者_运维百科

['DefinedContexts', 'DefinedContextsException', 'ElementException', 'ElementWrapper', 'GroupException', 'Groups', 'JSONSerializer', 'JSONSerializerException', 'Music21Exception', 'Music21Object', 'Music21ObjectException', 'Test', 'TestMock', 'VERSION', 'VERSION_STR', 'WEAKREF_ACTIVE', 'all', 'builtins', 'doc', 'file', 'name', 'package', 'path', 'abc', 'abj', 'analysis', 'articulations', 'bar', 'base', 'beam', 'chord', 'chordTables', 'clef', 'codecs', 'common', 'composition', 'configure', 'converter', 'copy', 'corpus', 'counterpoint', 'defaults', 'demos', 'derivation', 'doc', 'doctest', 'duration', 'dynamics', 'editorial', 'environLocal', 'environment', 'expressions', 'figuredBass', 'graph', 'humdrum', 'inspect', 'instrument', 'interval', 'intervalNetwork', 'json', 'key', 'layout', 'lily', 'mainTest', 'matplotlib', 'medren', 'metadata', 'meter', 'midi', 'musedata', 'musicxml', 'note', 'numpy', 'parse', 'pitch', 'ratios', 'repeat', 'roman', 'romanText', 'scale', 'serial', 'sieve', 'spanner', 'stream', 'sys', 'tempo', 'test', 'text', 'tie', 'tinyNotation', 'trecento', 'types', 'unittest', 'uuid', 'voiceLeading', 'xmlnode']

and in the IDE:

['author', 'builtins', 'date', 'doc', 'file', 'name', 'package', 'music21']


The path should be to the correct python executable, or its folder.


In Python, every directory than contains __init__.py is a package. And the sys.path contains the directories in which Python searches for the packages, so you should use

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

to be able to import music and other packages from that directory.


It looks like you've installed music21 inside a folder also called music21 and that latter (outside) folder is in your path in your IDE, but the inner folder is in your path in other cases. So when you type "import music21" in your IDE you've imported the outside folder and you'd need to type this obscure command "from music21 import music21" to get to the actual toolkit.

--

If "corpus" is the only problem you're seeing, I am guessing that you have two different versions of music21 installed and one of them was the "noCorpus" version of the toolkit from: http://code.google.com/p/music21/downloads/list

The only reason we've made a noCorpus version is that some of the files there are not world-wide Free software (they're all totally licensed for the US) and a Linux Dist. wanted to package music21 with it but couldn't include some of the corpus files. Unless you're really low on disk space or upholding Mexican copyright law of life+100, etc., you probably don't need the noCorpus version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜