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:
Open a command prompt.
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
.
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.
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 usingwhere python
in the command prompt.
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.