you’re in kinda luck i’ve got a hack, but it causes a minor delay at startup. was planning to look into it today, bizarre to stumble on this
i needed this for pyttsx3 for blender-text-to-speech addon but be warned it’s very much a hack so you may benefit from me investigating it. I’ll jot down my notes anyway and links to the code.
Step 1 - check for pyttsx3
First code to run in init.py I try and import pyttsx3 within a try-except block, and install it if it’s missing.
Step 2 - check for pywin32
Next is a similar try-catch to try import pywintypes, however if missing i had to install pypiwin32,
note the subtle difference i.e import pywintypes, pip install pypiwin32 and you will get pywin32… kinda almost
issue 1: .DDL files in wrong path
After install i found two .ddl files weren’t in the right path. I didn’t investigate why, I just moved the files but hopefully i just need to change my pip --target flag but I also found…
issue 2: new lib paths need to be added to sys.path
unsure what this is a side effect of or just confounder… for now i just check/add the paths
by the way…
***> if you can run blender with the system python environment might be much easier, you can delete the blender python dir to force blender to use the system wide install or you can open blender with the --python-use-system-env
flag just make sure the python versions are the same ***
back to Step 2 - check for pywin32- check for pywin32
Try import pywintypes in a try-except block. If it imports, hopefully it works and you can stop here.
A ModuleNotFoundError exception could mean multiple things so in that case I do a check to see if one of the .ddl files are where it’s meant to be. If the file is there, it’s been installed and just needs the lib paths to be appended
If the files aren’t there, it’s not installed, then I:
-
do the pip install of the module pypiwin32
-
move the ddl files:
pythoncom310.dll
pywintypes310.dll
Are installed into:
BASE/lib/pywin32_system32
But I found I needed them to be moved to:
BASE/lib/win32/lib
Where BASE is the path to blenders python interpreter, Which currently in windows I’m getting with:
Path(str(sys.executable)).parent.parent
(prior to version 2.92 you can use bpy.app.version
)
-
append the lib paths the sys path
It seems I added two paths to sys.path:
`BASE/lib/win32`
`BASE/lib/win32/lib`
surprisingly has worked across blender releases so I just forgot about it…
So if i had to guess it all stems from the ddl not being in the right place, maybe it’s all been fixed in the new blender i’ll try and do a bit more digging, it’s been years and I spotted atleast 1 careless bug…