i have ffmpeg in requrements and i downloaded the requrememts.txt everything downloaded including ffmpeg. i ran my program and it gives me that ffmpeg cant be found so i type pip install ffmpeg but it says its insalled i also tried with sudo apt install ffmpeg but it doesnt work i tried removing it and downloding it again but still doesnt work. I am talking about a python file. also the prgram works in vscode
Are you running the python program in a virtual environment in idx??
You need to use a virtual environment to run python program on idx… Won’t work without that
i think so it has the venv at the front
and also it runs but when it gets to the part where i request the ffmpeg it spits the error
If your are running it on a virtual environment then u shd be good… Not sure what might be causing it…
i menaged to get it installed by placeing pkgs.ffmpeg in the dev.nix but now it says that opus is not loaded but i have it installed
Edit: i added inport discord.opus <-this should not be needed and a print(discord.opus.is_loaded()) and it returns false which is strange
but now it says that opus is not loaded
Can you give us a snippet of the python program that causes that issue please? I just tried a basic setup below and was not able to repro.
- add pkgs.ffmepg to dev.nix
- Create a virtual environment and activate it, then install ffmepg with
pip install ffmpeg-python==0.2.0
- Run the following test script.
import ffmpeg
stream = ffmpeg.input('input.mp4')
stream = ffmpeg.hflip(stream)
stream = ffmpeg.output(stream, 'output.mp4')
ffmpeg.run(stream)
heres the whole error
Traceback (most recent call last):
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/ext/commands/core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/music-boss/main.py", line 104, in play
ctx.voice_client.play(player, after=lambda e: asyncio.run_coroutine_threadsafe(play_next(ctx), bot.loop))
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 487, in play
self.encoder = opus.Encoder(
^^^^^^^^^^^^^
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/opus.py", line 359, in __init__
_OpusStruct.get_opus_version() # lazy loads the opus library
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/opus.py", line 332, in get_opus_version
raise OpusNotLoaded()
discord.opus.OpusNotLoaded
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 1366, in invoke
await ctx.command.invoke(ctx)
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/ext/commands/core.py", line 1029, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/ext/commands/core.py", line 244, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OpusNotLoaded:
discord should load opus by default. I also have an check if opus is loaded at the start of the program and it loads false. The program continues to run until the user wants to do something. opus is not used when the program is idle or before user input. It works on my local machine.
Thanks for the detail! I think I found the issue. It seems like the system is having trouble finding the opus shared library in the Nix setting. Looking at the nix implementation of the python library, we can fix this by ptching the find library function with the explicit path to libopus.so.
To fix
- add pkgs.libopus to dev.nix
- In the workspace block in dev.nix, add the following onStart hook to patch the discord python library on every workspace start. This assumes that you have a virtualenvironment callt .venv and .venv/lib/python3.11/site-packages/discord/opus.py is where opus.py is. You may need to find the exact location of opus.py if it is different.
Tell me if that works.
onStart= {
patch-opus = ''
sed -i "s|ctypes.util.find_library('opus')|'${pkgs.libopus}/lib/libopus.so'|g" .venv/lib/python3.11/site-packages/discord/opus.py
'';
};
thanks for the response. I got the program running with your help. When testing when i use the play function (user is requred to type a name or a link and it pulls a song from youtube mainly and it plays it in the voice chat) at the start of the first test i get this error
(.venv) music-boss-8188723:~/music-boss$ /home/user/music-boss/.venv/bin/python /home/user/music-boss/main.py
False
2024-08-13 09:33:15 INFO discord.client logging in using static token
2024-08-13 09:33:16 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: 21431cedc538a71a918628ffaef419ce).
Logged in as Music Boss#2936 (ID: 1256918125455085649)
------
2024-08-13 09:33:32 INFO discord.voice_state Connecting to voice...
2024-08-13 09:33:32 INFO discord.voice_state Starting voice handshake... (connection attempt 1)
2024-08-13 09:33:32 INFO discord.voice_state Voice handshake complete. Endpoint found: bucharest7591.discord.media
2024-08-13 09:33:33 INFO discord.voice_state Voice connection complete.
2024-08-13 09:34:38 ERROR discord.voice_state Disconnected from voice... Reconnecting in 1.26s.
Traceback (most recent call last):
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/voice_state.py", line 598, in _poll_voice_ws
await self.ws.poll_event()
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/gateway.py", line 1037, in poll_event
raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code)
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4006
2024-08-13 09:34:40 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1223351723301540000 (Guild ID 1223351720587825233)
2024-08-13 09:34:40 INFO discord.voice_state Connecting to voice...
2024-08-13 09:34:40 INFO discord.voice_state Starting voice handshake... (connection attempt 1)
2024-08-13 09:34:40 INFO discord.voice_state Voice handshake complete. Endpoint found: bucharest7591.discord.media
2024-08-13 09:34:40 INFO discord.voice_state Voice connection complete.
2024-08-13 09:34:41 ERROR discord.voice_state Disconnected from voice... Reconnecting in 0.55s.
Traceback (most recent call last):
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/voice_state.py", line 598, in _poll_voice_ws
await self.ws.poll_event()
File "/home/user/music-boss/.venv/lib/python3.11/site-packages/discord/gateway.py", line 1037, in poll_event
raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code)
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4006
Ive never seen that happen before. This was when i played a 4min video. It gave the error like 10 time in a row while glitching slowing down going faster and reconnecting. (i have a function that reconnects bc it closes the connection in about 15-30 seconds)
On the second test tho it worked perfectly fine. I will do some more deveopment on it and report later on how its going. Also is there a way to make it not start the program when i open the workspace? I am looking at default.openFiles but i think this is just to open them in the editor not run them. Thanks for your help Alex.
EDIT:
I just noticed i forgot to mention but as you can see the first thing the program returns is False from the check is opus loaded. It returns false but it works very strange