AutoGPT: In speak mode: ModuleNotFoundError: No module named 'gi'

Duplicates

  • I have searched the existing issues

Steps to reproduce 🕹

  1. Install via vscode + devcontainer method (on WIndows), using stable branch
  2. Template .env with necessary API keys and ELEVENLABS voice IDs
  3. Start with --speak arg

speech.mpeg file is generated and saved to disk, but the below error occurs.

Current behavior 😯

Continue (y/n): Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/workspaces/Auto-GPT/autogpt/speak.py", line 112, in speak
    success = eleven_labs_speech(text, voice_index)
  File "/workspaces/Auto-GPT/autogpt/speak.py", line 55, in eleven_labs_speech
    playsound("speech.mpeg", True)
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 91, in _playsoundNix
    import gi
ModuleNotFoundError: No module named 'gi'

Beyond saying y, all further interactions are impossible (program freezes).

Expected behavior 🤔

No response

Your prompt 📝

N/A

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 10
  • Comments: 27

Most upvoted comments

I’m going to take a stab at this issue with the goals of:

  1. Discovering whether this is an environment-specific issue which belongs somewhere else (Docker, WSL2, VSCode) since OP and I have similar environments
  2. Finding a stable fix

Same issue here.

ModuleNotFoundError: No module named ‘gi’

The speech synthesis function activated with --speak argument, seems to rely on a gi module.

I managed to fix the error by adding PyGObject module in the requirements.txt. This is the name of the module when installed with pip (https://pypi.org/project/PyGObject/)

It also requires three dependency packages to be installed using apt:

  • libcairo2-dev
  • libgirepository1.0-dev
  • python3-gst-1.0

It can be done adding theses lines to the DockerFIle:

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    # Dependencies required for PyGObject pyhton module (used by ELEVENLABS speech synthesis)
    && apt -y install --no-install-recommends libcairo2-dev \
    && apt -y install --no-install-recommends libgirepository1.0-dev \
    && apt -y install --no-install-recommends python3-gst-1.0 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

It fixed the issues but now the command hangs after the AI name (without error):

vscode ➜ /workspaces/auto-gpt (feature/config-test) $ python -m autogpt --speak Speak Mode: ENABLED Welcome to Auto-GPT! Enter the name of your AI and its role below. Entering nothing will load defaults. Name your AI: For example, ‘Entrepreneur-GPT’ AI Name: Entrepreneur-GPT

I assume this due to a missing sound interface in the docker container, which makes sense. The next step would be to find a way to mount or link the host sound device inside the container…

Unfortunately the above solution didn’t work for me.

Continue (y/n): Traceback (most recent call last):
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 261, in <module>
    playsound(argv[1])
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 162, in _playsoundNix
    import gi
ModuleNotFoundError: No module named 'gi'
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/workspaces/Auto-GPT/autogpt/speak.py", line 112, in speak
    success = eleven_labs_speech(text, voice_index)
  File "/workspaces/Auto-GPT/autogpt/speak.py", line 55, in eleven_labs_speech
    playsound("speech.mpeg", True)
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 254, in <lambda>
    playsound = lambda sound, block = True: _playsoundAnotherPython('/usr/bin/python3', sound, block, macOS = False)
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 229, in _playsoundAnotherPython
    t.join()
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 218, in join
    raise self.exc
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 211, in run
    self.ret = self._target(*self._args, **self._kwargs)
  File "/home/vscode/.local/lib/python3.8/site-packages/playsound.py", line 226, in <lambda>
    t = PropogatingThread(target = lambda: check_call([otherPython, playsoundPath, _handlePathOSX(sound) if macOS else sound]))
  File "/usr/local/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '/home/vscode/.local/lib/python3.8/site-packages/playsound.py', 'speech.mpeg']' returned non-zero exit status 1.

As far as I know this issue remains unresolved - Commenting to remove the stale tag.

I’m working on it now. Very frustrating… I’m on Ubuntu 22, Python 3.10, Jetson Orin Nano Arm64 server. Exact same error.

Exception in thread Thread-2 (_speak): Traceback (most recent call last): File “/usr/lib/python3.10/threading.py”, line 1016, in _bootstrap_inner self.run() File “/usr/lib/python3.10/threading.py”, line 953, in run self._target(*self._args, **self._kwargs) File “/home/truth/AutoGPT/autogpts/autogpt/autogpt/speech/say.py”, line 50, in _speak success = self._voice_engine.say(text, voice_index) File “/home/truth/AutoGPT/autogpts/autogpt/autogpt/speech/base.py”, line 39, in say return self._speech(text, voice_index) File “/home/truth/AutoGPT/autogpts/autogpt/autogpt/speech/eleven_labs.py”, line 87, in _speech playsound(“speech.mpeg”, True) File “/root/.cache/pypoetry/virtualenvs/agpt-mdKPTkzc-py3.10/lib/python3.10/site-packages/playsound.py”, line 91, in _playsoundNix import gi ModuleNotFoundError: No module named ‘gi’

I uninstalled version 1.2.2 of playsound and pip reinstalled it which grabbed version 1.3.0. This fixed the speak issue in my environment. Should this issue be closed?

As far as I know this issue remains unresolved - Commenting to remove the stale tag.

I haven’t been able to solve the Gst namespace issue yet, running VS Code on Windows with a dev container

I uninstalled version 1.2.2 of playsound and pip reinstalled it which grabbed version 1.3.0. This fixed the speak issue in my environment. Should this issue be closed?

I am running Python 3.11.3 in a virtual environment within WSL2, ubuntu 20.04.

I originally was having issues as well with “gi” per the original issue description but I was able to get past that after installing pyobjc in my virtual environment:

pip install pyobjc

For reference, I am using playsound 1.2.2:

pip show playsound

Name: playsound Version: 1.2.2

This was then causing the following error to be thrown when the bot attempted to use TTS to the user:

Goals: [‘Increase net worth’, ‘Grow Twitter Account’, ‘Develop and manage multiple businesses autonomously’] Continue (y/n): Exception in thread Thread-1 (speak): Traceback (most recent call last): File “…/.pyenv/versions/3.11.3/lib/python3.11/threading.py”, line 1038, in _bootstrap_inner self.run() File “…/.pyenv/versions/3.11.3/lib/python3.11/threading.py”, line 975, in run self._target(*self._args, **self._kwargs) File “…/Auto-GPT/autogpt/speech/say.py”, line 33, in speak success = VOICE_ENGINE.say(text, voice_index) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “…/Auto-GPT/autogpt/speech/base.py”, line 33, in say return self._speech(text, voice_index) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “…/Auto-GPT/autogpt/speech/eleven_labs.py”, line 80, in _speech playsound(“speech.mpeg”, True) File “…/Auto-GPT/autogpt1/lib/python3.11/site-packages/playsound.py”, line 92, in _playsoundNix gi.require_version(‘Gst’, ‘1.0’) File “…/Auto-GPT/autogpt1/lib/python3.11/site-packages/gi/init.py”, line 126, in require_version raise ValueError(‘Namespace %s not available’ % namespace) ValueError: Namespace Gst not available ^CYou interrupted Auto-GPT Quitting…

[above code is edited to not have full path]

I was able to get past this by performing the following global in my linux environment:

sudo apt install python3-gst-1.0

This appears to get me past the errors being thrown but now it is hanging when attempting to get to the speak portion of dialog:

Goals: [‘Increase net worth’, ‘Grow Twitter Account’, ‘Develop and manage multiple businesses autonomously’] Continue (y/n): y Using memory of type: LocalCache Using Browser: chrome THOUGHTS: I think we should start by researching some potential business ideas that could help us increase net worth and grow our Twitter account. We can use the ‘google’ command to search for articles and resources on the topic. REASONING: Researching potential business ideas is a good starting point to help us achieve our goals. By using the ‘google’ command, we can quickly gather information and insights on different industries and markets. PLAN:

  • Use the ‘google’ command to research potential business ideas
  • Save important information to files for future reference CRITICISM: I need to ensure that I am not getting sidetracked by irrelevant information and that I am focusing on the most promising business ideas.

[HANGS HERE WITH NO OUTPUT]

aborting out shows:

^C Aborted! ^CException ignored in: <module ‘threading’ from ‘…/.pyenv/versions/3.11.3/lib/python3.11/threading.py’> Traceback (most recent call last): File “…/.pyenv/versions/3.11.3/lib/python3.11/threading.py”, line 1583, in _shutdown lock.acquire() KeyboardInterrupt:

So at this point it seems, atleast for my situation with WSL2, that the audio may not be getting passed from Windows to the Linux Subsystem correctly. I am going to continue down the rabbit hole, but not sure if I will get anywhere. Would just be easier at this point to create a virtualbox with Ubuntu and build it in there.

Posted my information here for future prosperity

I had to uninstall and reinstall the playsound library (version 1.3.0 seems to work for me)

See this related discussion