In this tutorial we will use venv
with 3ds Max.
The venv tool allows us to configure different independent Python execution
environments on our machine, each having its own set of installed pip packages.
The complete documentation for venv can be found here
as of Python 3.6, venv
is the preferred virtual environment tool for Python.
The Python embedded with 3ds Max includes the virtualenv tool, and we will be using that. Open a command prompt in the 3ds Max Python directory (typically something like C:\Program Files\Autodesk\3ds Max 202X\Python
) and create a virtual environment:
<maxpath>\Python\python.exe -m venv d:\myenv
Then activate it by running:
d:\myenv\Scripts\activate
At this point you will see the name of your virtual environment prefixing the command line:
(myenv) PS D:\myenv>
Start 3ds Max:
3dsmax.exe
From this moment we can use pip to add packages inside the virtual environment, from the virtual environment command line:
pip install somepackage
And we are able to import the installed package in 3ds Max:
import somepackage
Open a command prompt in your virtual environment directory:
PS D:\myenv> .\Scripts\activate
(myenv) PS D:\myenv> pip install numpy
Collecting numpy
Downloading numpy-1.21.0-cp37-cp37m-win_amd64.whl (13.9 MB)
|████████████████████████████████| 13.9 MB 3.3 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.21.0
(myenv) PS D:\myenv> & 'C:\Program Files\3ds Max 2022\3dsmax.exe'
Now inside 3ds Max, you can inspect sys.prefix to see that Python is using the virtual environment:
>>> import sys
>>> sys.prefix
'D:\\myenv'
>>> import numpy