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.
Related
I have a Python library in which I am setting up some tests. As parts of the tests I am using MagicMock to mock some features like JSON load and files openning and closing. The tests work, everything works as expected.
The issue comes when I try to run the tests with coverage. Since I introduced the new tests that use mock I get coverage crashing.
This is the part where I am implementing the mocking:
def setUp(self):
# Setup the content of the config files for the tests
json.load = MagicMock(side_effect=file_content)
# Opening a file returns the name of the file
def get_mock_context(filename):
mock_context = MagicMock()
mock_context.__enter__.return_value = filename
mock_context.__exit__.return_value = False
return mock_context
builtins.open = MagicMock(side_effect=get_mock_context)
As mentioned, when I run the tests everything seems to be working fine
python -m unittest discover -s tests -p "*Tests.py"
...........................
----------------------------------------------------------------------
Ran 27 tests in 1.322s
OK
Nonetheless, as soon as I introduce coverage:
coverage run -m unittest discover -s tests -p "*Tests.py"
...........................
----------------------------------------------------------------------
Ran 27 tests in 1.759s
OK
Traceback (most recent call last):
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 627, in do_run
self.run_python_module(args[0], args)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/execfile.py", line 122, in run_python_module
run_python_file(pathname, args, package=packagename, modulename=modulename, path0=path0)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/execfile.py", line 192, in run_python_file
exec(code, main_mod.__dict__)
File "/anaconda3/envs/c360/lib/python3.7/unittest/__main__.py", line 18, in <module>
main(module=None)
File "/anaconda3/envs/c360/lib/python3.7/unittest/main.py", line 101, in __init__
self.runTests()
File "/anaconda3/envs/c360/lib/python3.7/unittest/main.py", line 273, in runTests
sys.exit(not self.result.wasSuccessful())
SystemExit: False
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/envs/c360/bin/coverage", line 10, in <module>
sys.exit(main())
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 756, in main
status = CoverageScript().command_line(argv)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 491, in command_line
return self.do_run(options, args)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 641, in do_run
self.coverage.save()
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/control.py", line 782, in save
self.data_files.write(self.data, suffix=self.data_suffix)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/data.py", line 680, in write
data.write_file(filename)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/data.py", line 467, in write_file
with open(filename, 'w') as fdata:
File "/anaconda3/envs/c360/lib/python3.7/unittest/mock.py", line 951, in __call__
return _mock_self._mock_call(*args, **kwargs)
File "/anaconda3/envs/c360/lib/python3.7/unittest/mock.py", line 1017, in _mock_call
result = effect(*args, **kwargs)
TypeError: get_mock_context() takes 1 positional argument but 2 were given
I have no idea what the issue might be. I have tried excluding the lines in the tests files that include mocking with pragma: no cover but that did nothing. I cannot find a way to make this work again. Any ideas or something you think I might have missed?
EDIT:
I just cleaned a bit the code y pasted before. If I run coverage specifying that I want to to use as source only the files in my local directory (to avoid using coverage in python libraries etc) I get the following error. Still not working, but a different one:
Traceback (most recent call last):
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 627, in do_run
self.run_python_module(args[0], args)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/execfile.py", line 122, in run_python_module
run_python_file(pathname, args, package=packagename, modulename=modulename, path0=path0)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/execfile.py", line 192, in run_python_file
exec(code, main_mod.__dict__)
File "/anaconda3/envs/c360/lib/python3.7/unittest/__main__.py", line 18, in <module>
main(module=None)
File "/anaconda3/envs/c360/lib/python3.7/unittest/main.py", line 101, in __init__
self.runTests()
File "/anaconda3/envs/c360/lib/python3.7/unittest/main.py", line 273, in runTests
sys.exit(not self.result.wasSuccessful())
SystemExit: False
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/envs/c360/bin/coverage", line 10, in <module>
sys.exit(main())
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 756, in main
status = CoverageScript().command_line(argv)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 491, in command_line
return self.do_run(options, args)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/cmdline.py", line 641, in do_run
self.coverage.save()
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/control.py", line 781, in save
self.get_data()
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/control.py", line 834, in get_data
self._post_save_work()
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/control.py", line 864, in _post_save_work
self._find_unexecuted_files(src)
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/control.py", line 913, in _find_unexecuted_files
for file_path, plugin_name in itertools.chain(py_files, plugin_files):
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/control.py", line 910, in <genexpr>
py_files = ((py_file, None) for py_file in find_python_files(src_dir))
File "/anaconda3/envs/c360/lib/python3.7/site-packages/coverage/files.py", line 416, in find_python_files
del dirnames[:]
TypeError: 'tuple' object does not support item deletion
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?
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
I'm new to python and bdd and need some help, please. I'm trying to get junit reports from python behave, but after each test I got this error:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.5.4\helpers\pycharm\behave_runner.py", line 271, in <module>
_BehaveRunner(my_config, base_dir).run()
File "C:\Program Files (x86)\JetBrains\PyCharm 4.5.4\helpers\pycharm\_bdd_utils.py", line 96, in run
self._run_tests()
File "C:\Program Files (x86)\JetBrains\PyCharm 4.5.4\helpers\pycharm\behave_runner.py", line 189, in _run_tests
self.__real_runner.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\behave\runner.py", line 672, in run
return self.run_with_paths()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\behave\runner.py", line 693, in run_with_paths
return self.run_model()
File "C:\Program Files (x86)\JetBrains\PyCharm 4.5.4\helpers\pycharm\behave_runner.py", line 112, in run_model
return super(_RunnerWrapper, self).run_model(features)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\behave\runner.py", line 483, in run_model
failed = feature.run(self)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\behave\model.py", line 523, in run
failed = scenario.run(runner)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\behave\model.py", line 914, in run
self.stdout = runner.context.stdout_capture.getvalue()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\behave\runner.py", line 214, in __getattr__
raise AttributeError(msg)
AttributeError: 'Context' object has no attribute 'stdout_capture'
By the way flags in behave.ini are next:
[behave]
junit=True
stdout_capture=True
stderr_capture=True
I solve this. If you use ide to run test, as I do (PyCharm), then try to run it from command line and all should work fine.
I have installed pyPDF2 pyPdf-1.15 successfully installed when I open terminal and type these codes
import os
from PyPDF2 import PdfFileReader
path = "F:/Download"
inputFileName = os.path.join(path, "RealPython.pdf")
inputFile = PdfFileReader(open(inputFileName, "rb"))
Then this comes
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\pdf.py", line 797, in __init__
self.read(stream)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\pdf.py", line 1352, in read
xrefstream = readObject(stream, self)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py", line 71, in readObject
return DictionaryObject.readFromStream(stream, pdf)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py", line 587, in readFromStream
value = readObject(stream, pdf)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py", line 62, in readObject
return ArrayObject.readFromStream(stream, pdf)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py", line 158, in readFromStream
arr.append(readObject(stream, pdf))
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py", line 73, in readObject
return readHexStringFromStream(stream)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py", line 302, in readHexStringFromStream
txt += chr(int(x, base=16))
TypeError: int() got an unexpected keyword argument 'base'
I don't know what I'm doing wrong, any help?
Error: int() got an unexpected keyword argument 'base'. Most likely this is related to ironpython int function implementation. You can try to edit this file in PyPDF2 package: C:\Program Files (x86)\IronPython 2.7\lib\site-packages\PyPDF2\generic.py (line 302, in readHexStringFromStream). Pass 16 as second positional argument to int:
#txt += chr(int(x, base=16))
txt += chr(int(x, 16))