Psychopy gives the ffmpeg error and does not play the videos - python

I want to create an experiment with Psychopy in which I will present randomly video that participant will have to evaluate.
I have created a routine with my MovieStim and my Rating response and a Loop with my conditions file (in which are my video files videoname.wmv).
All my videos are in the same folder as my experiment.
I have specified the MovieStim with a variable refering to my Loop's column ($Stimulus).
But when I run the experiment I have this message.
Running: E:\Thèse ESPRIT\Approach_Aversion\Experience_AA\Approach_Aversion_lastrun.py
pyo version 0.8.0 (uses single precision)
WARNING:root:Warning: could not find imageio's ffmpeg executable:
[Error 5] Accès refus: 'C:\\Program Files (x86)\\PsychoPy2\\lib\\site-packages\\imageio\\resources\\ffmpeg\\ffmpeg.win32.exe'
Traceback (most recent call last):
File "E:\Thèse ESPRIT\Approach_Aversion\Experience_AA\Approach_Aversion_lastrun.py", line 105, in <module>
depth=0.0,
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\contrib\lazy_import.py", line 120, in __call__
return obj(*args, **kwargs)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\movie3.py", line 124, in __init__
self.loadMovie(self.filename)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\movie3.py", line 170, in loadMovie
self._mov = VideoFileClip(filename, audio=(1 - self.noAudio))
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 55, in __init__
reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 32, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 237, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "C:\Program Files (x86)\PsychoPy2\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Program Files (x86)\PsychoPy2\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] Le fichier spécifié est introuvable
It seems to be something wrong with the ffmpeg executable but I don't understand what.
Do you have any idea ?
Thank you very much fo advance !
Have a nice day.
Ivane

Related

WinError 32, Python, file used by another process

I have a script that is searching through files in a folder for multiple functions, one of which is verifying if they are valid. If they are corrupt, it moves them to another location. When trying to move the file, I get an error that it is being used by another process. I've looked through other similar questions, but none seem to resolve my issue.
path = filedialog.askdirectory()
pathbad = filedialog.askdirectory()
conv = os.path.basename(os.path.normpath(path))
bad = os.path.basename(os.path.normpath(pathbad))
jpg_list = []
badfiles = []
nojpg = []
cbz_list = [str(pp) for pp in path.glob("**/*.cbz")]
cbr_list = [str(pp) for pp in path.glob("**/*.cbr")]
file_list = cbr_list + cbz_list
for file in file_list:
if ('.cbr' in file) or ('.rar' in file):
try:
with rarfile.RarFile(file) as MyRar:
rarcontents = MyRar.namelist()
rarcontents = [x.lower() for x in rarcontents]
if any('.jpg' in s for s in rarcontents):
jpg_list.append(file)
else:
nojpg.append(file)
except (rarfile.BadRarFile):
badfiles.append(file)
except:
continue
if len(badfiles) > 0:
print('Moving ', len(badfiles), ' bad archives to "Bad Files":\n')
for zfile in badfiles:
nfile = zfile.replace(conv, bad)
shutil.move(zfile, nfile)
It errors on the shutil.move command. The file is actually copied to the new location, but not deleted from the old. I have verified that the file is not open in any application outside of python, and the only place it's open in python uses a with statement, which (as I understand it) closes the file when complete.
Edit:
Complete Stack Trace
File "C:\Program Files\Python39\lib\shutil.py", line 806, in move
os.rename(src, real_dst)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'Q:\\Download\\Comics\\Various Files\\Convert\\Poptropica 01.cbr' -> 'Q:\\Download\\Comics\\Various Files\\Bad Files\\Poptropica 01.cbr'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\azure\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\azure\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\azure\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Program Files\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Program Files\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "i:\dev\comix\cbz_JPG-to-WEBP.py", line 138, in <module>
shutil.move(zfile, nfile)
File "C:\Program Files\Python39\lib\shutil.py", line 827, in move
os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'Q:\\Download\\Comics\\Various Files\\Convert\\Poptropica 01.cbr'
If you are on windows open the task manager and close the python prosseses
Restart PC

win32com EnsureDispatch fails to load DLL at creating gen_py cache

My python code raises an error when creating the necessary gen_py folder in the \Appdata\Local\Temp\ directory. The error is raised when executing the following line:
Excel = win32com.client.gencache.EnsureDispatch('Excel.Application')
When executing this line (for the first time) the following error is raised:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 531, in EnsureDispatch
mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 515, in EnsureModule
module = MakeModuleForTypelib(typelibCLSID, lcid, major, minor, progressInstance, bForDemand = bForDemand, bBuildHidden = bBuildHidden)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 284, in MakeModuleForTypelib
makepy.GenerateFromTypeLibSpec( (typelibCLSID, lcid, major, minor), progressInstance=progressInstance, bForDemand = bForDemand, bBuildHidden = bBuildHidden)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\makepy.py", line 279, in GenerateFromTypeLibSpec
gen.generate(fileUse, bForDemand)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\genpy.py", line 822, in generate
self.do_generate()
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\genpy.py", line 885, in do_generate
oleItems, enumItems, recordItems, vtableItems = self.BuildOleItemsFromType()
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\genpy.py", line 750, in BuildOleItemsFromType
oleItem, vtableItem = self._Build_Interface(type_info_tuple)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\genpy.py", line 718, in _Build_Interface
oleItem = DispatchItem(info, attr, doc)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\genpy.py", line 270, in __init__
build.DispatchItem.__init__(self, typeinfo, attr, doc)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\build.py", line 115, in __init__
self.Build(typeinfo, attr, bForUser)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\build.py", line 262, in Build
fdesc = typeinfo.GetFuncDesc(j)
pywintypes.com_error: (-2147312566, 'Fout bij laden van type DLL-bestand.', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python\file.py", line 659, in <module>
start()
File "D:\Python\file.py", line 55, in start
AE_addPivotTables(str_filename, df_opzet)
File "D:\Python\file.py", line 556, in AE_addPivotTables
Excel = win32com.client.gencache.EnsureDispatch('Excel.Application')
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 538, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process - please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run makepy manually for this object
Manually running the makepy process raises the same error.
After this error I see in the directory \Appdata\Local\Temp\ that the folder 'gen_py' has been created with the expected files in the cache. However my code is not dispatching excel yet because when I run the script a second time the following error is raised:
Traceback (most recent call last):
File "D:\Python\file.py", line 659, in <module>
start()
File "D:\Python\file.py", line 55, in start
AE_addPivotTables(str_filename, df_opzet)
File "D:\Python\file.py", line 556, in AE_addPivotTables
Excel = win32com.client.gencache.EnsureDispatch('Excel.Application') # Excel = win32com.client.Dispatch('Excel.Application')
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 531, in EnsureDispatch
mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 388, in EnsureModule
module = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 263, in GetModuleForTypelib
AddModuleToCache(typelibCLSID, lcid, major, minor)
File "C:\Program Files (x86)\Python\lib\site-packages\win32com\client\gencache.py", line 549, in AddModuleToCache
dict = mod.CLSIDToClassMap
AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9' has no attribute 'CLSIDToClassMap'
It seems that the first error raised when creating the gen_py folder results in a cache that cannot be used. The problem seems to be in loading DLL files by pywintypes.com.
I tried this solution of a similar problem: https://github.com/ContinuumIO/anaconda-issues/issues/37
I copied the .dll files from the map C:\Program Files (x86)\Python\Lib\site-packages\pywin32_system32 to C:\Program Files (x86)\Python\Lib\site-packages\win32\lib. However this did not solve the issue.
Is there a way to solve this error?
Thanks in advance!
EDIT: Removing and re-installing Python and all necessary packages did not resolve the issue.

AttributeError using python module py3270

As a part of some automation I am trying to connect to mainframe using python, where I can access the mainframe files and create a
report. Just like using mainframe files as DB for python program.
To login to mainframe - we need to provide host details(xyz.host.com)
followed with region details(h123p) and then with our credentials.
I found that we can do this using python package py3270 and tried doing it but getting the error.
from py3270 import Emulator
# or not (uses s3270)
em = Emulator()
em.connect('xyx.example.com')
em.fill_field(3, 1, 'xxxx',5)
em.send_enter()
em.fill_field(2, 1, 'xxxxxxx', 7)
em.send_enter()
em.fill_field(8, 20, 'xxxxxxxx', 8)
em.send_enter()
# if your host unlocks the keyboard before truly being ready you can use:
em.wait_for_field()
# maybe look for a status message
if not em.string_found(1, 2, 'login succesful'):
abort()
# do something useful
# disconnect from host and kill subprocess
em.terminate()
The error:
File "C:/Users/vganr/PycharmProjects/test/mainframe.py", line 6, in
<module>
em = Emulator()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 273, in __init__
self.app = app or self.create_app(visible, args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 291, in create_app
return Ws3270App(args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 140, in __init__
self.spawn_app()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 145, in spawn_app
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 775,
in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 1178,
in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Exception ignored in: <function Emulator.__del__ at 0x038CB810>
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 285, in __del__
self.terminate()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 320, in terminate
if not self.is_terminated:
AttributeError: 'Emulator' object has no attribute 'is_terminated'
Based on the error messages you're seeing, I suspect you're having a problem with missing/not found x3270/s3270 libraries.
return Ws3270App(args)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 140, in __init__
self.spawn_app()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\py3270
\__init__.py", line 145, in spawn_app
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 775,
in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python37-32\lib\subprocess.py", line 1178,
in _execute_child
startupinfo)
The above suggests that the library is trying to start Ws3270, the windows version of x3270, and is unable to do so.
Make sure the the required libraries are in your path and visible from python.

The system cannot find the file specified (Python 3)

I'm trying read texts from an image using pytesseract but it throws this error no matter what I try.
Code:
import os
import subprocess
import pytesseract
from PIL import Image
subprocess.call('dir', shell=True)
print(os.path.isfile("test.jpg")) #True
im = Image.open("test.jpg")
text = pytesseract.image_to_string(im)
OUTPUT:
Traceback (most recent call last):
File "F:/Programming/PYTHON/captcha/test/main.py", line 10, in <module>
text = pytesseract.image_to_string(im)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 193, in image_to_string
return run_and_get_output(image, 'txt', lang, config, nice)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 140, in run_and_get_output
run_tesseract(**kwargs)
File "F:\Program Files (64bit)\Python\lib\site-packages\pytesseract\pytesseract.py", line 111, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "F:\Program Files (64bit)\Python\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "F:\Program Files (64bit)\Python\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Process finished with exit code 1
what's wrong? I know that file is there. I checked it using os.path.isfile and subprocess call
Other things that I tried:
-added full image file path using string literal 'r'
-tried different images and file types

distutils.dir_util.copy_tree expects a file in destination before copying

I want to copy the contents of one directory to another, using copy_tree function for doing this. Below is my code:
copy_tree('/opt/Deployment/scripts/image', '/opt/Deployment/dist-packages/job-123')
A couple of files from the directory image are getting copied into job-123, but after that, I get this error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rpyc/core/protocol.py", line 305, in _dispatch_request
res = self._HANDLERS[handler](self, *args)
File "/usr/local/lib/python2.7/dist-packages/rpyc/core/protocol.py", line 535, in _handle_call
return self._local_objects[oid](*args, **dict(kwargs))
File "/usr/local/lib/python2.7/dist-packages/rpyc/core/service.py", line 157, in exposed_execute
execute(text, self.exposed_namespace)
File "<string>", line 2, in execute
File "<string>", line 5, in <module>
File "../installModel.py", line 17, in <module>
copy_tree('/opt/Deployment/scripts/image', '/opt/Deployment/dist-packages/job-123')
File "/usr/lib/python2.7/distutils/dir_util.py", line 163, in copy_tree
verbose=verbose, dry_run=dry_run))
File "/usr/lib/python2.7/distutils/dir_util.py", line 167, in copy_tree
dry_run=dry_run)
File "/usr/lib/python2.7/distutils/file_util.py", line 148, in copy_file
_copy_file_contents(src, dst)
File "/usr/lib/python2.7/distutils/file_util.py", line 44, in _copy_file_contents
fdst = open(dst, wb)
IOError: [Errno 2] No such file or directory: /opt/Deployment/dist-packages/job-123/lib/utils.pyc
Now this file utils.pyc is in the source directory in the lib subdirectory, it should get copied to the same subdirectory in the destination. Why is copy_tree expecting it to be there already and throwing an error?

Categories

Resources