Blender can't load ctypes from system Python (not embedded Python).

Hello, I have tried my best to figure out what is going on and Blender can’t load the ctypes modules (which btw used by many other libraries), but still I can’t see what is going wrong.

Here is the sys.path output


>>> import sys
>>> sys.path


# I have formatted the output so it's readable
'C:\\Programs\\Blender'
'C:\\Programs\\Blender\\2.75\\scripts\\addons'
'C:\\Programs\\Blender\\2.75\\scripts\\addons\\modules'
'C:\\Programs\\Blender\\2.75\\scripts\\freestyle\\modules'
'C:\\Programs\\Blender\\2.75\\scripts\\modules'
'C:\\Programs\\Blender\\2.75\\scripts\\startup'
'C:\\Programs\\Blender\\python34.zip'
'C:\\Python34'
'C:\\Python34\\DLLs'
'C:\\Python34\\lib'
'C:\\Python34\\lib\\site-packages'
'C:\\Users\\cos\\AppData\\Roaming\\Blender Foundation\\Blender\\2.75\\scripts\\addons\\modules'

However the problem is that some specific platform libraries can’t load, like ctypes. This line works great in IDLE but not in Blender.


>>> import ctypes
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Python34\lib\ctypes\__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError: DLL load failed: %1 is not a valid Win32 application.

About the environment variables, I use these:

This works, python and pip works great on the system.

PATH = C:\Python34;C:\Python34\Scripts

I found that using only this one I don’t need to put each Python related directory explicitly.

PYTHONHOME = C:\Python34

Any ideas?

One very strange bug!

I removed the PYTHONHOME environment variable because everyone said that Blender automatically recognizes the Python installation, environment variables should be set only if there is a need to override paths. Funny thing is that Blender if run directly from it’s location can boot up nicely (without any environment variable), but if it’s run from a shortcut in desktop won’t boot at all and won’t locate the system Python.

Well, other than that I used this environment variable this time BLENDER_SYSTEM_PYTHON as suggested here


and this sort of fixed things and now Blender can boot up from shortcut nicely, also it says that it found bundled python in C:\Python34.

However still gives me error:


>>> import ctypes
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Python34\lib\ctypes\__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError: DLL load failed: %1 is not a valid Win32 application.

What do you suggest? One idea I have is to erase everything related to Python and Blender and start again. If there is something fishy configurations that were left from the past they might produce this error.

Is your separate Python instance 32 or 64 bits? Maybe there’s an issue with that, if it’s 64bit and ctypes can only use 32bits.

Thanks for pointing this detail, I have installed the 64 bit version just in case.

Also I have managed to figure out what the problem was, I renamed the Python34.dll as well (the one that located aside with the blender.exe) so now everything is working fine.