Simon Lowes
Simon Lowes

Reputation: 37

Don't understand why I can't import music21

I am new to Python so I could perhaps learn the basics first... I'm a musician and keen to learn how to use Python with music.

I installed Python 3.8 x64 for Windows 10. I then used pip to install music21.

Opened the Python Shell, typed import music21 and got this:

    Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import music21
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import music21
  File "D:\Python\lib\site-packages\music21\__init__.py", line 170, in <module>
    from music21 import base
  File "D:\Python\lib\site-packages\music21\base.py", line 94, in <module>
    from music21 import common
  File "D:\Python\lib\site-packages\music21\common\__init__.py", line 39, in <module>
    from music21.common.parallel import *
  File "D:\Python\lib\site-packages\music21\common\parallel.py", line 19, in <module>
    from music21.ext.joblib import Parallel, delayed  # @UnresolvedImport # type: ignore
  File "D:\Python\lib\site-packages\music21\ext\joblib\__init__.py", line 119, in <module>
    from .parallel import Parallel
  File "D:\Python\lib\site-packages\music21\ext\joblib\parallel.py", line 32, in <module>
    from .externals.cloudpickle import dumps, loads
  File "D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\__init__.py", line 3, in <module>
    from .cloudpickle import *
  File "D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\cloudpickle.py", line 167, in <module>
    _cell_set_template_code = _make_cell_set_template_code()
  File "D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\cloudpickle.py", line 148, in _make_cell_set_template_code
    return types.CodeType(
TypeError: an integer is required (got type bytes)

I have found example code to run with music21 but I can't use it if I get errors.

Hope someone can help. Apologies if I'm being a complete n00b. Did look at other questions but didn't find or didn't understand the answers.

Upvotes: 1

Views: 1757

Answers (2)

music21 v5 does not support Python 3.8 -- choose 3.7 or download the latest Git from github.

EDIT: v5.7.2 now supports 3.8

Upvotes: 1

olivercollins-inhome
olivercollins-inhome

Reputation: 25

So from your output, the main piece that seems most useful is the TypeError: an integer is required (got type bytes) in the _make_cell_set_template_code function in the D:\Python\lib\site-packages\music21\ext\joblib\externals\cloudpickle\cloudpickle.py file. This issue could be an issue with music21 not being compatible with Python 3.8. I'm reading the documentation from https://web.mit.edu/music21/ and it says v.5 support Python 3.4-3.6, so I would try to get on one of those versions and restart the process you did to get to the step above. Hope this helps!

Upvotes: 1

Related Questions