Mayapy DLL Missing when loading module

Hi everybody
Here is some informations
Python 2.7, x64, pyHook-1.5.1-cp27-cp27m-win_amd64.whl setup using pip

And here is the result

Full code

def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module(‘_cpyHook’, [dirname(file)])
except ImportError:
import _cpyHook
return _cpyHook

    if fp is not None:
        try:
  		print pathname
  		_mod = imp.load_module('_cpyHook', fp, pathname, description)
        finally:
            fp.close()
        return _mod
_cpyHook = swig_import_helper()
del swig_import_helper

And this is where the error occurred

_mod = imp.load_module(‘_cpyHook’, fp, pathname, description)

This is very strange because in the line before

fp, pathname, description = imp.find_module(‘_cpyHook’, [dirname(file)])

it still recognize the module

Why did this happened? Why mayapy can’t import the module the same way python standalone can? It has the same core is python 27, right?
Thanks

The problem you’re running into is that the python version shipped by autodesk is using a different C-runtime version than the standard windows python. Basically autodesk compiled it with VS2012, and the standard Python2.7 is compiled with VS2008.
This means you’d need to recompile the _cpyHook module with the proper compiler so that it works inside Maya, or look for a pure python alternative.

1 Like

Hi R.White
Thank you for pointing that out, what is the “proper compiler” mean?

Maya 2014 requires VS2010
Maya 2015-2017 requires VS2012.
I looks like Maya 2018 bumped up to VS2015, but for whatever reason the compiled modules we’ve got are working fine in 2017 and 2018. So maybe Microsoft finally got around to stabilizing their runtime ABI a bit. I probably wouldn’t count on this being 100% fact though.

1 Like

Hi R.White

pyHook / Wiki / PyHook_Build_Instructions

There is a intruction post about build the package, however, i don’t see any of these step have VS include. Is this the right way to do it?

Thanks

I compiled it for you and put it up on Google Drive.

Feel free to grab it!

2 Likes

Omg, can you please tell me how to do it? please?
Since there is a few modules i need to re-compile as well

GitHub - Travis-Sun/pywin32: python for windows extensions

Thank you very much

Compiling packages is not easy. Some packages are straightforward to compile. Most require modifications and lots of trial and error.

First, you’ll need to get a copy of Microsoft Visual Studio 2015. Without it you can’t compile. I use a pro license at work, there might be a free/affordable “home” edition you can get.

Second, you’ll need to get a distribution of Python 2.7 built with Visual Studio 2015 (to match Maya 2018). You can use mayapy.exe, but some packages require specific headers and libraries you won’t have without the full Python dist. Luckily for you somebody did the hard work for you here.. You can download his version of Python built for VS2015… or you can try to get by with mayapy.exe. If you stick with mayapy and the package you’re trying to compile complains about missing Python headers and libraries, using his version will fix that.

Whether you use mayapy.exe or a custom build of python, make sure the interpreter’s location (mayapy.exe/python.exe) is in your system path.

Third, all packages that need to be compiled require you to set your environment variables so that distutils knows where to find your compiler’s libraries. To do that you need to run one or more .bat scripts buried in your VS2015 install folder. With some Googling you’ll find which you need, as I can’t remember off the top of my head.

If you want to save yourself a lot of problems, go grab a copy of Intel® Parallel Studio XE. You don’t need to buy it, just register and download the 30 day trail. This will give you a nice 64bit environment shell you can use to compile and save you a lot of pain.

At this point you have all the basics covered to start compiling. Once you have the source code to a package you want to compile, look for a readme file that will give you some info about dependencies and how to build. Sometimes you can get lucky, navigate to the source code, run “python.exe setup.py build” and it’ll work. But most times this won’t be the case. That is when you need to use some Google-fu.

pywin32 is one of those packages that will not be easy to compile.

Fortunately there are kind souls out there have shared their knowledge and experience with the internets for free! Even if their goals don’t match yours (this last link is for VS2012), there is still something in there you can learn from. With a little luck doing a few tweaks (like just changing the path to the compiler) might get it to work for you.

Sometimes you get even luckier and find a gift from the heavens in the form of a fork off the source code that claims has been modified to work with the compiler you need.

So that’s all I got for you at this point. When I get in the office on Monday I can take a swing at compiling it for you, and if you have a list of packages you need, I might be able to help further.

But just on a final note: there’s a reason why there’s no central depot of every python package compiled to work with Maya 20xx, it’s because it’s not easy :slight_smile:

Good luck!

2 Likes

Hello!
Could you please point me on python 2.7 v.1700 64 bit VC 2012 build binary anywhere in web?
I found this link How to build Python 2.7.5 using Visual Studio 2012 Express on Windows 8 64-bit, but it needs VS 2012 and seems to be complicated.
I wonder if anybody has a proper binary python 2.7 for windows?
Regards,
Oleg Solovjov

It is complicated. :slight_smile:

Try this version

It was built with VS2010 for Maya 2014. So this is not what you requested but does import and seems to work Maya 2018 (so presumably 2015-16-17 also).

I make no guarantees that you won’t run into issues, but if it helps you get what you need then it’s worth trying.

Also, consider using comtypes as an alternative. It is a pure python package that can do some of the things you might be trying to do with pywin32.

1 Like

Hi Fnord,
Good to see you again, unfortunately, it not work with maya 2017.
I have tried

  • install pywin32 x64 with pip using mayapy
  • replace the new package
  • This is the error that i got

Traceback (most recent call last):
File “”, line 1, in
File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-pa
import pywintypes
File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-pa
import_pywin32_system_module(“pywintypes”, globals())
File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-pa
raise ImportError(“No system module ‘%s’ (%s)” % (modname
ImportError: No system module ‘pywintypes’ (pywintypes27.dll)