Virtual Environments and 3ds Max Python

3ds Max 2021 and higher supports using virtual environments with Python 3, which allows you to ensure specific Python modules are loaded. This can be very useful for tools that have version-specific dependencies, and you need them to run in controlled environments. When a virtual environment is active, the Python interpreter in 3ds Max will search it first for imported modules - it becomes the first path on sys.path.

To set up a virtual environment, you need to create it outside of the 3ds Max application, using the 3ds Max Python interpreter, and then start 3ds Max from the same command prompt. To start 3ds Max with a virtual environment:

  1. Open a command prompt.

  2. Install the virtualenv module using the 3ds Max Python interpreter: C:\Program Files\Autodesk\3ds Max 2021\Python37\python.exe -m pip install --user virtualenv

    Note See "Using pip with Python 3" in Python extension libraries for instructions on how to install pip.

  3. Create a new virtual environment (this only needs to be done once): C:\Program Files\Autodesk\3ds Max 2021\Python37\python.exe -m virtualenv d:\myenv Once the environment has been created, you can install the specific modules you require.

  4. Activate the virtual environment (this needs to be done every time you start 3ds Max): d:\myenv\Scripts\activate.bat

    Note: You can deactivate the virtual environment using the deactivate.bat script in the same directory. You can view the path for any active virtual environment by using where python in the command prompt.

  5. Start 3ds Max: 3dsmax.exe

    Note: 3ds Max must be started in the same command prompt that ran activate.bat, as that script affects the local environment variables.

For more general information about using a virtual environment, see the Python documentation for Installing Packages using pip and virtual environments.