Heres the code I'm running:
from playsound import playsound
import threading
threading.Thread(target=playsound, args=('Assets\Loss.mp3',)).start()
When I run this it gives me this error
Error 259 for command:
play "Assets\Loss.mp3" wait
The driver cannot recognize the specified command parameter.
Error 305 for command:
close "Assets\Loss.mp3"
Cannot specify extra characters after a string enclosed in quotation marks.
Failed to close the file: "Assets\Loss.mp3"
Traceback (most recent call last):
File "C:\Users\ekila\Downloads\Smart Auto Bet\Test.py", line 10, in <module>
playsound('Assets\Loss.mp3')
File "C:\Python310\lib\site-packages\playsound.py", line 73, in _playsoundWin
winCommand(u'play {}{}'.format(sound, ' wait' if block else ''))
File "C:\Python310\lib\site-packages\playsound.py", line 64, in winCommand
raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
Error 259 for command:
play "Assets\Loss.mp3" wait
The driver cannot recognize the specified command parameter.
What's a little bit more interested is that when I move the mp3 to the same folder and run
from playsound import playsound
import threading
threading.Thread(target=playsound, args=('Loss.mp3',)).start()
It plays perfectly fine with no errors but I want to have the mp3 stored in the subdirectory
I have playsound version 1.2.2 installed.
I've tried running it without threading
Related
I want to add some sound using playsound, and it worked for a while with no issues. But when I tried to run the code today, it suddenly gave me this error. There are no spaces in the file names.
MacOS Big Sur 11.2.2
Python 3.9.6
from playsound import playsound
playsound('/Volumes/sDesktop/learnPython/2020simulator/Elegy_AsherFulero.mp3', block = False)
name#names-MBP 2020simulator % /usr/local/bin/python3 "/Volumes/sDesktop 1/learnPython/2020simulator/testScript5.py"
Traceback (most recent call last):
File "/Volumes/sDesktop 1/learnPython/2020simulator/testScript5.py", line 7, in <module>
playsound('/Volumes/sDesktop/learnPython/2020simulator/Elegy_AsherFulero.mp3', block = False)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/playsound.py", line 67, in _playsoundOSX
raise IOError('Unable to load sound named: ' + sound)
OSError: Unable to load sound named: file:///Volumes/sDesktop/learnPython/2020simulator/Elegy_AsherFulero.mp3
name#names-MBP 2020simulator %
well try and re-write the file name or click on the file and click properties.
copy the name and see the file type in the shortcut way next to the text where the () are, in there will be file type - delete the file name in the code and paste it then go back to properties and copy the file type in () and paste it after the file name in the code (no spaces)
or put the audio file in the same directory and delete the path and only include only the file name and the file type. if neither of these work then uninstall playsound -
pip uninstall playsound
and install in the same path as the py file by using the -t function
pip install -t directory playsound
---------paste the directory here
thanks.
I am having trouble with PyInstaller. I am trying to build the main file (Logical.py -> Logical.exe). When I run the file as a python script it runs fine (terminal: python Logical.py examples/led.lgc). When I run the exe built by PyInstaller (terminal: ./Logical examples/led.lgc), I get this error message:
Traceback (most recent call last):
File "Logical.py", line 2, in <module>
from pynput import keyboard
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[10688] Failed to execute script Logical
It appears to be upset about the pynput import, though I have no idea why. The imports of my source are below. loading and ui are both in the project directory and simpleANSI's source code is listed at the bottom of this post.
import sys, time, os, ctypes
from pynput import keyboard
from loading.loading import loadElement
from ui import vec2, widget, ansiManager
import simpleANSI as ANSI
import pdb
I run both of these repositories so I can guarantee that they will not change until I can get this fixed.
Full project source code - https://github.com/AwesomeCronk/Logical
Main file - https://github.com/AwesomeCronk/Logical/blob/master/Logical.py.
simpleANSI source code - https://github.com/AwesomeCronk/simpleANSI
I am using Python 3.9.5 on Windows 10 x64, PyInstaller version 4.3, pynput version 1.7.3.
EDIT: I dug through the Python lib files and found the destination of the traceback. This is the offending function in ...\python\3.9.5\Lib\site-packages\pynput\_util\__init__.py:
def backend(package):
"""Returns the backend module for a package.
:param str package: The package for which to load a backend.
"""
backend_name = os.environ.get(
'PYNPUT_BACKEND_{}'.format(package.rsplit('.')[-1].upper()),
os.environ.get('PYNPUT_BACKEND', None))
if backend_name:
modules = [backend_name]
elif sys.platform == 'darwin':
modules = ['darwin']
elif sys.platform == 'win32':
modules = ['win32']
else:
modules = ['xorg']
errors = []
resolutions = []
for module in modules:
try:
return importlib.import_module('._' + module, package)
except ImportError as e:
errors.append(e)
if module in RESOLUTIONS:
resolutions.append(RESOLUTIONS[module])
raise ImportError('this platform is not supported: {}'.format( # AwesomeCronk: This is the offending line
'; '.join(str(e) for e in errors)) + ('\n\n'
'Try one of the following resolutions:\n\n'
+ '\n\n'.join(
' * {}'.format(s)
for s in resolutions))
if resolutions else '')
I tried adding --hidden-import "pynput.keyboard._win32" --hidden-import "pynput.mouse._win32" to the PyInstaller args to no avail. I wound up rolling back pynput to version 1.6.8.
I have a python code that I wanted to turn into an exe.
I used pyinstaller with : pyinstaller --onefile -w script.py
After it finished making the exe file I double clicked the file but I got "Failed to execute script".
I also tried running it from the cmd but it gives the same fatal error.
Stuff to add:
The code imports a couple of files packages including a python code I made, as well as it makes files referenced to it's location.
Is there something I'm doing wrong?
the script has those imports:
import socket
import os
from PIL import ImageGrab
import cv2
import time
import json
import myFile
I ran the code under cmd and it gives this error:
File "script.py", line 3, in <module>
from PIL import ImageGrab
ModuleNotFoundError: No module named 'PIL'
Might be unrelated but now that I tried to do pyinstaller --onefile -w client.py.
After I ran it windows defender found this inside :
after running it in the terminal in pycharm with :
pyinstaller --onefile --hidden-import=PIL --hidden-import=Pillow --hidden-import=pynput client.py
I get this error (note that i moved it from the dist directory to the main one):
Traceback (most recent call last):
File "client.py", line 7, in <module>
import myFile
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "myFile.py", line 1, in <module>
from pynput import mouse, keyboard
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 82, in backend
ImportError
[13364] Failed to execute script client
This may be due to pyinstaller not being able to properly find your dependencies and skipping some packages.
To fix any error like ModuleNotFoundError: No module named 'PIL' just add it as a hidden import:
pyinstaller --onefile --hidden-import=PIL -w script.py
For the second error this is a known issue with pyinstaller and pynput.
Find here some explanation.
The TLDR of it seems to be that you need to add --hidden-import=pynput.mouse._win32 --hidden-import=pynput.keyboard._win32 --hidden-import=pynput._util._win32 and any other sub-packages that give you errors.
Recently I was working with the module pyautogui when I got an error, at first I dismissed it but then when I tried to run other programs the same error, referring to the pyautogui program popped up even though the other program had nothing to do with pyautogui. This was all in VSC, so after opening and closing VSC a few times and the error still occurred when I imported any module I decided to build my programs in terminal instead. The same error shows up. Below I have pasted the error from my terminal which will still not allow me to make any python module import whatsoever. Any help is greatly appreciated.
I have upgraded, uninstalled, and reinstalled everything and still the same
>>> import random
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Aezene\random.py", line 15, in <module>
StartLocation = pyautogui.locateOnScreen('Start.png')
File "C:\Users\Aezene\AppData\Roaming\Python\Python39\site-packages\pyautogui\__init__.py",
line 175, in wrapper
return wrappedFunction(*args, **kwargs)
File "C:\Users\Aezene\AppData\Roaming\Python\Python39\site-packages\pyautogui\__init__.py",
line 213, in locateOnScreen
return pyscreeze.locateOnScreen(*args, **kwargs)
File "C:\Users\Aezene\AppData\Roaming\Python\Python39\site-packages\pyscreeze\__init__.py",
line 359, in locateOnScreen
screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return
accurate coordinates, so don't pass a region here.
File "C:\Users\Aezene\AppData\Roaming\Python\Python39\site-packages\pyscreeze\__init__.py",
line 134, in wrapper
raise PyScreezeException('The Pillow package is required to use this function.')
pyscreeze.PyScreezeException: The Pillow package is required to use this function.
>>>
This happens because you haven't downloaded the "Pillow" package. You can download by using the command "pip install Pillow" or by using the following code:
from subprocess import *
from sys import *
call([executable, "-m", "pip, "install", "Pillow"])
You need to have this module because pyautogui's code won't run without it. If you install PyCharm and look at PyAutoGui's file code, you'll see that it is necessary to install the module
I recently came across the playsound module and I tried my Python IDE in my Raspbian os it's giving me some error:
from playsound import playsound
playsound('/home/pi/mu_code/music.mp3')
This code is getting me error:
Traceback (most recent call last):
File "/home/pi/mu_code/pl.py", line 2, in <module>
playsound('/home/pi/mu_code/music.mp3')
File "/home/pi/.local/lib/python3.7/site-packages/playsound.py", line 92, in _playsoundNix
gi.require_version('Gst', '1.0')
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gst not available
Try using double bars rewriting the mp3 path and tell me if it works. If it doesn't, try using the absolute path instead of a shorter one.
from playsound import playsound
playsound('//home//pi//mu_code//music.mp3')