AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

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

Open yegors opened this issue 1 year ago • 22 comments

Duplicates

  • [X] 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

yegors avatar Apr 15 '23 20:04 yegors

Same issue here.

scottswaaley avatar Apr 16 '23 00:04 scottswaaley

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

m4vr0x avatar Apr 16 '23 04:04 m4vr0x

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

See this related discussion

fdebrain avatar Apr 16 '23 18:04 fdebrain

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.

yegors avatar Apr 16 '23 18:04 yegors

Unfortunately the above solution didn't work for me.

Hum.. the error seems to be the same on your side. Did you delete your container + image and re-build it ?

m4vr0x avatar Apr 17 '23 01:04 m4vr0x

The error is different + more verbose from the initial post. I'll try it on another machine see if I can reproduce it.

yegors avatar Apr 18 '23 00:04 yegors

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?

dmkilday avatar Apr 21 '23 22:04 dmkilday

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?

MMcCormick avatar Apr 22 '23 04:04 MMcCormick

@dmkilday I tried your solution, unfortunately it was not successful for me while running in a dev container.

I'm using autogpt outside a container at this point, which appears to work as expected.

yegors avatar Apr 22 '23 17:04 yegors

Yes, I am not in a container either. Perhaps the issue is docker specific.

On Sat, Apr 22, 2023, 11:26 AM Yegor S @.***> wrote:

@dmkilday https://github.com/dmkilday I tried your solution, unfortunately it was not successful for me while running in a dev container.

I'm using autogpt outside a container at this point, which appears to work as expected.

— Reply to this email directly, view it on GitHub https://github.com/Significant-Gravitas/Auto-GPT/issues/1697#issuecomment-1518711984, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFDDA32KU35RFB2DUQNS753XCQICVANCNFSM6AAAAAAW7T4DW4 . You are receiving this because you were mentioned.Message ID: @.***>

dmkilday avatar Apr 22 '23 18:04 dmkilday

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

DouglasC2022 avatar Apr 24 '23 23:04 DouglasC2022

@DouglasC2022 thanks for posting, I came to a similar conclusion. I'm wondering if there's a solution external to Auto-GPT, but I haven't been able to hunt one down re: WSL2.

MMcCormick avatar Apr 25 '23 01:04 MMcCormick

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

MMcCormick avatar Apr 27 '23 07:04 MMcCormick

On macOS this requires pip3 install PyObjC, but this does not work running from Docker because that's a separate environment. I'm on latest autogpt 0.3.0. Is there any way PyObjC could be added as a dependency when sys.platform == "darwin"?

tgrushka avatar May 07 '23 18:05 tgrushka

I'm having this issue as well when using Docker and when using a VSCode Dev Container. Tried some of the fixes from this thread with no success.

kmnunley avatar May 07 '23 19:05 kmnunley

Since this issue does seem to be happening for other people, I wanted to mention a couple things I found while trying to debug

  • It seems like the problem is the virtual env communicating with the sound drivers of the base OS. I have similar issues whether trying to run with --speak directly from WSL2, from Docker, or a VSCode Dev Container.
  • Based on my searches, a common solution for WSL users is to use PulseAudio https://github.com/microsoft/WSL/issues/5816

If you get PulseAudio or another solution working, or happen to know the common solution for piping audio out of a container, please report back!

MMcCormick avatar May 08 '23 15:05 MMcCormick

This worked for me (Windows, using virtualenv): pip uninstall playsound pip install playsound==1.2.2

ankerelite avatar May 09 '23 00:05 ankerelite

This worked for me (Windows, using virtualenv): pip uninstall playsound pip install playsound==1.2.2

This doesnt work for me -- can you comment on how you have your setup configured? are you using WSL2? python version?

DouglasC2022 avatar May 15 '23 02:05 DouglasC2022

still getting the following error: Traceback (most recent call last): File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/local/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/app/autogpt/speech/say.py", line 23, in speak success = voice_engine.say(text, voice_index) File "/app/autogpt/speech/base.py", line 33, in say return self._speech(text, voice_index) File "/app/autogpt/speech/gtts.py", line 20, in _speech playsound("speech.mp3", True) File "/usr/local/lib/python3.10/site-packages/playsound.py", line 91, in _playsoundNix import gi ModuleNotFoundError: No module named 'gi'

JosephWJMaxwell avatar May 15 '23 17:05 JosephWJMaxwell

This worked for me (Windows, using virtualenv): pip uninstall playsound pip install playsound==1.2.2

This doesnt work for me -- can you comment on how you have your setup configured? are you using WSL2? python version?

I believe that the people who are able to fix it by installing the correct playsound version are not using WSL2. I'm not able to resolve my issue with either version of playsound, which is why I think this issue is separate from the one mentioned here:

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

See this related discussion

MMcCormick avatar May 16 '23 06:05 MMcCormick

This worked for me (Windows, using virtualenv): pip uninstall playsound pip install playsound==1.2.2

This doesnt work for me -- can you comment on how you have your setup configured? are you using WSL2? python version?

Nope not using WSL2, python v3.11 (sorry for late reply!)

ankerelite avatar May 16 '23 17:05 ankerelite

Hi all, after searching a lot and trying different things here's what i've done that resolved the issue. First i made sure i had sound working in WSL2 (ubuntu) : look for /mnt/wslg tried playing speech.mpeg with vlc => ok install gstreamer : sudo apt install gst123

  • installed sudo apt install gstreamer1.0-adapter-pulseeffects gstreamer1.0-alsa
  • pip uninstall playsound
  • pip install playsound

After that : python -m autogpt --speak worked

using python 3.11

dallgoot avatar May 24 '23 16:05 dallgoot

This issue has automatically been marked as stale because it has not had any activity in the last 50 days. You can unstale it by commenting or removing the label. Otherwise, this issue will be closed in 10 days.

github-actions[bot] avatar Sep 06 '23 21:09 github-actions[bot]

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

MMcCormick avatar Sep 11 '23 01:09 MMcCormick

This issue has automatically been marked as stale because it has not had any activity in the last 50 days. You can unstale it by commenting or removing the label. Otherwise, this issue will be closed in 10 days.

github-actions[bot] avatar Nov 12 '23 01:11 github-actions[bot]

This issue was closed automatically because it has been stale for 10 days with no activity.

github-actions[bot] avatar Nov 22 '23 01:11 github-actions[bot]

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'

TruthTrill avatar Feb 17 '24 07:02 TruthTrill

I don't know if your problem is exactly the same as mine, but I'll share the process I went through to fix the gi module error when using playsound. The environment I was working in is a GitHub code space.

  1. Install Required System Packages First, install the necessary system packages to use the gi module and the Gst (GStreamer) namespace. For Ubuntu/Debian-based systems, use the following commands:

sudo apt-get update sudo apt-get install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0 sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gir1.2-gstreamer-1.0

  1. Set Up Virtual Environment With the virtual environment activated, install PyGObject:

pip install PyGObject

  1. Set Environment Variable Set the GI_TYPELIB_PATH environment variable so that the gi module can find the necessary type libraries:

export GI_TYPELIB_PATH="/usr/lib/girepository-1.0"

Entering this command in the terminal will apply it only to the current session. To make it permanent, add it to your ~/.bashrc file:

echo 'export GI_TYPELIB_PATH="/usr/lib/girepository-1.0"' >> ~/.bashrc source ~/.bashrc

This may resolve the issues with the gi module and allow you to use the Gst namespace in your Python scripts.

yeoul2023 avatar Aug 07 '24 08:08 yeoul2023