[Maya 2018] - import python package


I would like to use the portalocker package in my tool. I am coding on a Mac and have very little to no Windows 10 experience. I run into the following issue, where if I install the package globally on the Mac the tool works but if I do the same on the PC it doesn’t.

Thanks for the help.

This has to do with the fact that the osx version of Maya uses the system python, but on windows it uses an interpeter bundled with Maya. Even if you have installed a python 27 in Windows and you pip-install the package to it, Maya won’t see it without extra help.

Generally if you want to distribute tools across both platforms you have to figure out a good way to vendor external dependencies–besides the question of installs, there is also the fact that on windows, linux and OS X packages often include different binary dependencies – and on Windows, you can’t count on Pip being able to recompile those for you. Windows users often have to chase around finding the correct prebuilt binaries for their environment. On all platforms you’d have to do extra work to make sure that different users got the correct versions as well.

For all these reasons people generally don’t rely on pip-install to set up a team wide Maya toolkit. (see Installing Python packages for use within Maya, for example). The most common alternative is to do an audit of a blank system python, pip install into it, and then copy out all the files that were added by the install (often, pip will install a bunch of dependencies even though you only thought you were installing one package). Most often these will land in Lib/site-packages

When you copy out the installed stuff you’ll need to distribute it alongside your tools. Maya modules are a common way to do this. One thing to avoid if you can is doing too much path-fiddling in your startup scripts – that’s a common shortcut but it often causes problems if multiple tools try to do things to the path in turn/