-
Notifications
You must be signed in to change notification settings - Fork 45
USD in a virtualenv
For the purposes of this tutorial, we are going to assume that all our work is going to happen in $HOME/usd-sandbox
. We are also going to set an environment variable indicating the root of your virtual env. You can name it as you wish, here's one possibility.
USDVENVNAME=venv-27May
USDVENV=$HOME/usd-sandbox/$USDVENVNAME
Before you start, make sure that cmake 3.12 or newer are installed on your machine, and active in your path. You can verify it by typing cmake --version
.
Building USD in a virtualenv is most robust when the installation is completely self-contained and does not rely on globally available resources, such as a system installation of Python. A good way to achieve this is to install a version of Python in a non-global place, using an installer from https://python.org. Install virtualenv:
pip install virtualenv
You will need to create a virtualenv once, and you will subsequently activate it whenever you wish use that environment for development or running usd tools.
I suggest naming the virtual env something like usd-20.05-env. Create it as follows:
cd $HOME/usd-sandbox
virtualenv $USDVENVNAME
Activate it on mac or linux using the activate script.
source $USDVENV/bin/activate
Typing which python
should allow you to verify that the python in use is within the usd-20.05-env directory hierarchy. In our case, $USDVENV/bin/python
. Whenever you need to leave this environment you can either close your shell, or source the deactivate script, i.e. $USDVENV/bin/deactivate
.
Windows is similar, except there are batch files.
After your virtual environment is created, verify that the following files exist.
$USDVENV/
+--- ...
+---/include/
+--- ...
+--- pyconfig.h
+---/lib/
+--- ...
+--- libpython2.7.dylib
Depending on the phase of the moon, include and lib may be nested one layer deeper, in a directory indicating python version such as +---/python27
. "Phase of the moon" means that the implementation details change underfoot frequently, so it's always necessary to double check.
If the files are not there, you will need to copy them manually into those locations.
It is possible that pip is not functional in the virtualenv for reasons outside of your control. To test this, cd $USDVENV/bin
and type pip
. If pip isn't recognized as a command, we need to install pip into the environment. You may need to sudo.
cd $USDVENV/bin
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
After this step, running pip
should succeed.
Install USD's pythonic preferences into the active virtual environment. Note that by default, pip will install packages in the virtualenv, in a location that the virtual env cannot actually see them without creating .pth files. Let's avoid that issue, and instruct pip to install the packages into the site-packages folder. If you are using Python 2.7, this will look like this:
pip install PySide2 -d $USDVENV/lib/python2.7/site-packages
pip install PyOpenGL -d $USDVENV/lib/python2.7/site-packages
Note! -d is not an option in some versions of pip. If the preceding lines result in an error, the much simpler commands should work:
pip install PySide2
pip install OpenGL
Double check $USDVENV/lib/python2.7/site-packages to verify that PySide2, shiboken, and PyOpenGL actually landed there. If they didn't please file an issue on usd-build-club.
cd $HOME/usd-sandbox
git clone https://github.com/PixarAnimationStudios/USD.git
Ensure you are on the branch you wish to work with. For example, if you are working in the dev branch:
cd USD
git checkout dev
Now that the environment has been created, set up, activated, and cloned, build USD:
python $HOME/usd-sandbox/USD/build_scripts/build_usd.py -v $USDVENV
When the dust settles, you are almost done. Set PATH and PYTHONPATH as instructed by the build output.
These steps have been shown to work on MacOS and Windows, but not yet on Linux. See this issue: https://github.com/PixarAnimationStudios/USD/issues/1162