How to resolve 'PATH' KeyError when importing AudioSegment from pydub in Python?

This topic was automatically generated from Slack. You can find the original thread here.

when I try to do this import in a Python step:

from pydub import AudioSegment

I get this error:

Traceback (most recent call last):

  File "/nano-py/server.py", line 71, in <module>
    worker.load()

  File "/nano-py/pipedream/worker.py", line 100, in load
    self.step_modules[cell["id"]] = importlib.import_module(cell["importPath"])

  File "/var/lang/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 850, in exec_module

  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed

  File "/tmp/__pdg__/dist/code/500ea0a773bf6d5d86a910fddcb52b87c7f8d787be986a6da4518cda1745e371/code.py", line 5, in <module>
    from pydub import AudioSegment

  File "/tmp/__pdg__/dist/python/pydub/__init__.py", line 1, in <module>
    from .audio_segment import AudioSegment

  File "/tmp/__pdg__/dist/python/pydub/audio_segment.py", line 152, in <module>
    class AudioSegment(object):

  File "/tmp/__pdg__/dist/python/pydub/audio_segment.py", line 163, in AudioSegment
    converter = get_encoder_name()  # either ffmpeg or avconv

  File "/tmp/__pdg__/dist/python/pydub/utils.py", line 164, in get_encoder_name
    if which("avconv"):

  File "/tmp/__pdg__/dist/python/pydub/utils.py", line 152, in which
    envdir_list = [os.curdir] + os.environ["PATH"].split(os.pathsep)

KeyError: 'PATH'

How can I solve this?

I’m sorry, but it seems that the pydub package requires binaries that are not compatible with the Pipedream workflow environment. Unfortunately, we cannot support these types of packages at this time. If you have an issue importing a PyPI package into a Python code step, please open an issue at Sign in to GitHub · GitHub.

I tried this but got the same error:

# pipedream add-package pydub

from pydub import AudioSegment

I apologize for the confusion. As I mentioned earlier, the pydub package requires binaries that are not compatible with the Pipedream workflow environment. Unfortunately, we cannot support these types of packages at this time. If you have an issue importing a PyPI package into a Python code step, please open an issue at Sign in to GitHub · GitHub.