Using external Python libraries with Maya Python

If you want to use libraries external to Maya in your Python scripts, you will have to add them either to your PYTHONPATH environment variable before you start Maya, or add them to the system path by calling sys.path.append() from within your Python interpreter.

You can set your PYTHONPATH environment variable within your Maya.env file or in your environment before starting Maya. If you have set PYTHONPATH both in Maya.env and in your system environment variables, the value of PYTHONPATH set in your system environment will always take precedence over the value you set in Maya.env.

The Maya.env file is located in C:\Users\<Username>\Documents\maya\<version_number>\ on Windows, $HOME/maya/<version_number>/ on Linux, and $HOME/Library/Preferences/Autodesk/maya/<version_number>/ on macOS.

For more information on PYTHONPATH, see File path variables.

To add libraries to the Python system path from within the Python interpreter, use sys.path.append()
import sys sys.path.append( '<Path_To_Libraries>' )

You can also add the call to sys.path.append() in a start up script such as userSetup.py.