Getting Started With Python and RenderMan

If you're just starting out as a Python RenderMan programmer, here is what you need:

If you have all this up and running already, great! Next step is How to Use the RManDev programs.

1. Python, editor or IDLE

You need to have Python 2 or 3 installed and be able to run Python programs from the command line. On Linux this is bash, usually called Terminal in the desktop menus. On MacOS, it is the Terminal application in the Utilities subfolder. On MS Windows, it is PowerShell, but I'm going to call it the Terminal anyway. (You could use the old Command Prompt instead, but PowerShell is much better.)

You also need a plain text editor to write and modify Python programs with. This could be emacs, nano, Sublime, TextPad, TextWrangler - use whatever you are comfortable with. Or you could use the standard Python IDLE as your editor.

Python is built-in to most versions of Linux and MacOS. From the Terminal you should be able to do this

/home/hugh% python
Python 2.7.8 (default, Sep 24 2015, 18:26:19)
[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

The RManDev programs should work with either Python 2, which is still the default at time of writing on MacOS, or Python 3.

On MS Windows you have to install Python yourself. Download the Python binary installer that matches your system, which in 2017 is almost certainly Python 3 (64 bit).

When you run the Installer, on the third Customize Python screen look for the option

Add python.exe to Path

and make sure it is selected.

Once the installer has finished, you should be able to open PowerShell and do the same as above:

PS C:\Users\hugh> python
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

2. RenderMan from the command line

If you're reading this you presumably already have RenderMan.

On MacOS, the command line preview display server won't run unless you have the X11 libraries. Download the XQuartz installer. And you'll have to log out and back in again.

Although RenderMan is installed, you still need to ensure that you can run the various RenderMan programs from the command line.

From your terminal, command prompt, or shell you should be able to do something like this:

/home/hugh/HelloRenderMan% ptrender
Usage: ptrender [options] ptcfile channelname outfile
Options:
...

If you get an error message about not being able to find ptrender, you need to add RenderMan to your path. Again this varies from system to system.

On my Linux laptop I added these lines to my /home/hugh/.bashrc file:

export RMANTREE="/opt/pixar/RenderManProServer-21.5"
export PATH="$RMANTREE/bin:$PATH"
export LD_LIBRARY_PATH="$RMANTREE/lib:$LD_LIBRARY_PATH"

On MacOS I added almost identical lines in my /Users/hugh/.bash_profile file. Use a plain text editor, and create the file if necessary. The period at the start of the file name is important, and also means that it won't show up in the Finder.

export RMANTREE="/Applications/Pixar/RenderManProServer-21.5"
export PATH="$RMANTREE/bin:$PATH"
export LD_LIBRARY_PATH="$RMANTREE/lib:$LD_LIBRARY_PATH"

On MS Windows, open the System Control Panel, the Advanced tab, and finally click on Environment Variables

System Control Panel

Create a new user variable:

New RMANTREE variable

Create or edit the PATH environment variable, and set or append the RenderMan bin folder:

Edit PATH variable

If the PATH variable already existed, the new value using %RMANTREE% needs to be added with a semicolon between it and existing values.

On all three of Linux, MacOS, and MS Windows updates to your PATH don't automatically take effect. Close your Terminal window and open a new one. (Or reload the environment variables if you know how.)

3. RenderMan from Python

The next step is to make RenderMan usable from Python programs. Start Python and type:

Type "help", "copyright", "credits" or "license" for more information.
>>> import prman
>>>

If you get an ImportError, the RenderMan Python package needs to be added to your Python module search path. On Linux or MacOS you should add this line to your .bashrc or .bash_profile. (Yes, the bin directory.)

export PYTHONPATH="$RMANTREE/bin:$PYTHONPATH"

On MS Windows you need to create or update the PYTHONPATH environment variable. Click through the Control Panel, Advanced Settings, Envioronment Variables dialogs as above until you can create:

Edit PYTHONPATH variable

4. Assembling images into a movie

The output from RenderMan is a series of single frame image files, so you'll need a program that can assemble these into a movie file of some kind. On Linux, ffmpeg and ImageMagick convert will work, but you may have to hunt down codecs for H.264 first. On MS Windows I've used Movie Maker, and on MacOS iMovie. No doubt there are many other applications that can also be used.

5. Pillow Python Imaging Library

This is a package for image manipulation in Python. You don't absolutely have to have it, but it is very useful for working with texture, shadow, and height maps. To test whether it is installed, start Python from the command line and type:

Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>

If you got an error message, try installing the package. Unfortunately how to do this varies from system to system, and whether you have administrator rights or not. Follow the online instructions. It is worth your time figuring out how to install PIL, because once you can do that, you will be able to install a wide variety of other useful Python packages. But if it gets awkward, don't worry and leave it for later.

You are ready for How to Use the RManDev programs.


Suggestions, mistakes, other feedback?

Any and all feedback about this gratefully accepted.

hugo.fisher@gmail.com.

Copyright 2017 Hugh Fisher, Canberra. Released under Creative Commons Attribution-NonCommercial-ShareAlike license.