KatsBits
Creating 3D models, meshes & game content
3D modelling & meshing, level editing and textures making
Hints, tips and tutorials for 3D modelling & content creation

[back]Setting up the Python Path system variable

Contents
What is Python? ^

Although most scripts that run from Blender - either included when you install the application or 3rd party scripts created or downloaded - don't necessarily need the Python API to be installed you may, during the course of using Blender 3D, find that a number of the more 'complex' Python *.py scripts don't run reporting various 'runtime' errors.

This, thankfully, is usually to do with the script trying to access a Python 'variable' that's either not included with Blender or with the script being run, and if the script doesn't have any other syntax errors, is usually easy to fix by installing the full Python API and setting up Python's 'system variable'.

The tutorial below walks through the simple steps to setting Windows XP systems.

It's basically a programming language that has a long history that forms part of a computer system Operating Environment; Microsoft's 'Windows' environment is a notable exception which is why it often needs to be installed. Linux and Mac OS users shouldn't need to install Python.

The Python 'system variable' (python 'path')? ^

Basically we need to set a 'system variable' for Windows so it, and programs that use Python, know where to look for the files and modules installed.

The Python variable is a collection of 'file paths' to various 'module' locations within the API root directory; for the sake of simplicity the example shown below are the path sections associated with an installation of Python to C:\Python22;

C:\PYTHON22;C:\PYTHON22\DLLs;C:\PYTHON22\LIB;C:\PYTHON22\LIB\LIB-TK

It's also sometimes written as follows;

C:\\PYTHON22;C:\\PYTHON22\DLLs;C:\\PYTHON22\LIB;C:\\PYTHON22\LIB\\LIB-TK

But either method should work.

How to set up the Python path

If you find that you need to set up the Python system variable then the following information will tell you how to do it

System Properties ^

If you have the 'My Computer' icon on your desktop right click on that and select 'Properties', this should open the following dialogue box displaying the 'General' page by default. Find the tab at the top of the window called 'Advanced' and click to select that page. On this page at the bottom is a button saying 'Environment Variable', click that button.

Design note : If you don't have the 'My Computer' desktop icon click 'Start > Control Panel' and then double click on the 'System' icon. You should then be able to follow the remain instructions.

The 'Advanced' page in 'System Properties' dialogue
The 'Advanced' page in 'System Properties' dialogue
Environment Variables ^

The window that opens when clicking the 'Environment Variables' button in the Advanced tab lists a number of variables - their names and 'values' (usually a file path) - installed by other applications; you normally don't need to be in this part of Windows; this is a notable exception.

This dialogue is split into two sections; the upper part are 'User' variables to do with the current logged on user; the lower half being 'System' or 'system wide' variables that apply to everyone/thing using the computer. It's here that we need to create a 'new' variable.

Current system variables installed by other applications
Current system variables installed by other applications
Creating a new variable ^

In the lower half click on the 'New' button to open the 'Add/Edit' input dialogue.

Creating a new system variable
Creating a new system variable

Enter the following details, which may vary depending on where you have Python installed;

  • Variable Name
    • PythonPath
  • Variable Value
    • C:\PYTHON22;C:\PYTHON22\DLLs;C:\PYTHON22\LIB;C:\PYTHON22\LIB\LIB-TK

Design note : If you've installed Python to a 'longer' file path; i.e. somewhere other than your 'root' drive then you will need to use the old 'dos' system where by words, names or path segments longer than 8 characters get truncated. For example;

C:\Program Files\Python22\

gets truncated to;

C:\Progra~1\python22\

Keep this in mind if you find that after entering the file paths used in the system variable it doesn't work. Double check you've used the correct path, locations and 'syntax' (method of writing the path).

Also note that if you've installed Python 2.3.x or 2.4.x then you'll need to change the file path appropriate to that as well; the path mentioned in this tutorial is relative to the installation of Python 2.2x, hence 'PYTHON22' which is the folder the API is installed to.

'System Variable' details entered ^

Once you add in the details you should end up with something similar to the image below which shows the new variable 'name'; 'PYTHONPATH' and it's 'value'; "C:\PYTHON22; etc...".

The new variable 'name' and 'value'
The new variable 'name' and 'value'

Once this is done you can 'OK' the procedure which will return you to the initial 'Environment Variables' dialogue window.

You should now see, in the lower section, a new item listed (you may need to scroll the window depending on what else is listed) similar to that shown below. Once you see this you can 'OK' this window to return back to the main 'System Properties' dialogue window.

If at this point (or some point in the future) you see an error in the variable information either double click or select it and hit 'Edit' to amend the entry. 'OK' once you're done.

The new variable in place
The new variable in place
Python path and other Operating Systems? ^

Basically yes. If you're running Windows XP (Home or Pro) you shouldn't need to restart your computer; Windows 95/98/ME/2000 users, on the other hand may need to reboot to set the variable in place.

Once all this is complete you should find that, baring any code errors, scripts will now run correctly.

Design note : Not all scripts are coded to run on the latest Python versions so check the readme's and/or info that came with the script to make sure you're using a compatible version of Python and Blender.

© 2008 KatsBits - All Rights reserved.
No part of this web site may be reproduced (unless for personal use) without prior written consent from KatsBits.com
Privacy Policy | Advertise