Skip to content

Do You Have Questions?

Explore this few ones

Can't find the answer you're looking for? Check our Practical Guides, Code Examples, or Getting Started documentation.

kernpy FAQ Illustration


Detailed Answers

1. How do I install kernpy?

The easiest way is to use pip:

pip install kernpy

For the latest development version:

pip install git+https://github.com/OMR-PRAIG-UA-ES/kernpy.git

See Getting Started for more options.


2. I get ModuleNotFoundError when importing kernpy. What should I do?

  1. Verify it's installed: pip show kernpy
  2. Reinstall if needed: pip install --force-reinstall kernpy
  3. Check your Python environment:
  4. If using a virtual environment, ensure it's activated
  5. Check python --version matches the command you installed with
  6. Try importing with absolute path: python -c "import kernpy; print(kernpy.__version__)"

3. What Python versions does kernpy support?

kernpy requires Python 3.9 or later. Check your version with:

python --version

4. What file formats does kernpy support?

kernpy primarily supports kern and mens notation in Humdrum format (.krn, .mens, .ekrn, etc.). All must be plain text files.

kernpy reports parsing issues as warnings, not fatal errors. You can usually still work with the document:

import kernpy as kp

doc, errors = kp.load('score.krn')
if errors:
    print(f"Found {len(errors)} issues, but loaded doc has {doc.measures_count()} measures")

To be strict about errors:

try:
    doc, errors = kp.load('score.krn', raise_on_errors=True)
except ValueError as e:
    print(f"Fatal parsing error: {e}")

5. What's the difference between load() and loads()?

  • load(filename) — Reads from a file on disk
  • loads(string) — Parses from a string already in memory

Choose based on your data source:

# From disk
doc, errors = kp.load('score.krn')

# From a string or variable
content = "**kern\n*M4/4\n4c\n*-"
doc, errors = kp.loads(content)

6. How do I transpose a score?

Use the to_transposed() method:

import kernpy as kp

doc, _ = kp.load('score.krn')

# Transpose up a perfect 4th
transposed = doc.to_transposed('P4', 'up')
kp.dump(transposed, 'transposed.krn')

# Transpose down
transposed_down = doc.to_transposed('M2', 'down')

See Transposition Guide for all intervals.


7. How do I filter out certain types of information?

Use token categories:

import kernpy as kp

doc, _ = kp.load('score.krn')

# Remove decorations (articulations)
kp.dump(doc, 'no_decorations.krn',
        exclude={kp.TokenCategory.DECORATION})

# Keep only core music
kp.dump(doc, 'core_only.krn',
        include={kp.TokenCategory.CORE,
                 kp.TokenCategory.SIGNATURES,
                 kp.TokenCategory.BARLINES})

See Token Categories for details.


8. How do I extract just one spine or instrument?

import kernpy as kp

doc, _ = kp.load('score.krn')

# By type
kp.dump(doc, 'kern_only.krn', spine_types=['**kern'])

# By index
kp.dump(doc, 'first_spine.krn', spine_ids=[0])

# Multiple spines
kp.dump(doc, 'first_two.krn', spine_ids=[0, 1])

9. The library seems slow when processing many files. Any tips?

  1. Process in parallel using Python's multiprocessing:
from multiprocessing import Pool
import kernpy as kp

def process(filename):
    doc, _ = kp.load(filename)
    # ... do something
    return result

with Pool(4) as p:
    results = p.map(process, file_list)
  1. Use batch operations instead of loops where possible
  2. Profile with Python's built-in profiler:
import cProfile
cProfile.run('kp.load("large_file.krn")')

For large files running out of memory:

  1. Process by measures instead of loading entire document
  2. Use filtering to reduce data size:
kp.dump(doc, 'smaller.krn',
        spine_types=['**kern'],  # Only notes
        exclude={kp.TokenCategory.DECORATION})  # No extra data

10. What happened to the old API functions?

These older functions are deprecated. Use the modern API instead:

Old New Purpose
read() load() Read file from disk
create() loads() Parse from string
export() dumps() Export to string
store() dump() Write to file

See API Reference for migration details.

Old code example:

# OLD (deprecated)
doc = HumdrumImporter().import_file('score.krn')

# NEW (recommended)
doc, errors = kp.load('score.krn')

Still Have Questions?

If you don't find your answer here:

  1. Check the full documentation
  2. Search GitHub Issues for similar questions
  3. Create a new issue if needed

Don't hesitate to contact us! 😊

Found something wrong? Have a suggestion? We'd love to hear from you!

Open an Issue on GitHub

Or visit our research group website to learn more about kernpy and related projects.