Home > Blockchain >  Cannot import name 'structures' from partially initialized module 'music'
Cannot import name 'structures' from partially initialized module 'music'

Time:12-19

I'm trying to use the package music, and I installed it using pip3 install music. It installed the dependencies correctly, but now with a sample code like the following

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))

I get the following error

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)

CodePudding user response:

It seems there is a bug in setup.py of the package. If you navigate to the folder where the package was installed you'll see that it contains files only

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

But according to the source code it also has sub-packages

|   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

After I copied missing folders to the folder where the package is installed at least I was able to import music, but your code still doesn't work for me, I am getting NameError: name 'Clarinet' is not defined.

  • Related