python-3.x 无法从部分初始化的模块“music”导入名称“structures”

1l5u6lss  于 2022-12-20  发布在  Python
关注(0)|答案(1)|浏览(216)

我尝试使用包music,我使用pip3 install music安装了它。它正确地安装了依赖项,但现在使用了如下所示的示例代码

from music import *

# create a clarinet
clarinet = Clarinet()

# create a song
song = Song()

# add notes to the song
song.addNote(Note('C4', QUARTER))
song.addNote(Note('D4', QUARTER))
song.addNote(Note('E4', QUARTER))

我收到以下错误

Traceback (most recent call last):
  File "ex.py", line 3, in <module>
    from music import *
  File "/home/norhther/.local/lib/python3.8/site-packages/music/__init__.py", line 1, in <module>
    from . import utils, tables, synths, effects, structures, singing, core
ImportError: cannot import name 'structures' from partially initialized module 'music' (most likely due to a circular import) (/home/norhther/.local/lib/python3.8/site-packages/music/__init__.py)
xxslljrj

xxslljrj1#

看起来包的setup.py中有一个bug。如果你导航到安装包的文件夹,你会看到它只包含文件

|   effects.py
|   synths.py
|   tables.py
|   utils.py
|   __init__.py

但根据the source code,它还有子包

|   effects.py
|   synths.py
|   tables.py
|   utils.py
|   __init__.py
|
+---core
|       classes.py
|       functions.py
|       synths.py
|       __init__.py
|
+---legacy
|   |   __init__.py
|   |
|   \---pieces
|           testSong2.py
|           __init__.py
|
+---singing
|       bootstrap.py
|       perform.py
|       __init__.py
|
\---structures
    |   permutations.py
    |   sumfree.py
    |   symmetry.py
    |   __init__.py
    |
    \---peals
            base.py
            peals.py
            plainChanges.py
            __init__.py

我复制丢失的文件夹到安装包的文件夹后,至少我能够import music,但你的代码仍然不为我工作,我得到NameError: name 'Clarinet' is not defined .

相关问题