Content is copyright © KatsBits™ 2000-2013. All Rights Reserved.
No part of this web site may be reproduced (except for personal use) without prior written permission from KatsBits.com. For more infomation on copyright click here.
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 adding Python's 'system environment variable'.
The following tutorial explains how to set up Python Path environment variable on Windows based computers.
Note: the installation and set up of Python is exactly the same irrespective of the version being installed, just substitute your version numbers, "Python27", "Python31" and so on, instead of "Python22" as used below.
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.
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;
It's also sometimes written as follows;
But either method should work.
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 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
In the lower half click on the 'New' button to open the 'Add/Edit' input dialogue.
Creating a new system variable
Enter the following details, which may vary depending on where you have Python installed;
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;
gets truncated to;
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.
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'
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
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.
To check, edit or add the Python Path system variable to Windows Vista PC's open 'Control Panel' from the 'Start' Menu and click 'System and Maintenance', 'System' then on the left hand side, click 'Advanced system settings', the properties panel that opens should be on "Advanced" by default, if not, click that and then the 'Environment Variable...' button at the bottom of the page. Continue on with the rest of the addition as outlined above.
Because Python API is constantly being improved and updated with new features and functionality it doesn't necessarily mean the system is backwards compatible; newer versions of Python won't necessarily be compatible or work with older (or newer) versions of Blender. This raises the question "how do I find out what version of Python I need to install with Blender?". The answer is quite straightforward. Blender tells us.
Note: so long as a given version of Python is installed to its respective folder or directory it's possible to install several version of the API to cater to specific versions of Blender (which can also be similarly installed).
Open Blender 3D and check the Console. You should see a few lines of text, the first is the important one as that tells you exactly what version of Python needs to be installed for that particular version of Blender.
Blender command prompt console
Blender 2.45 requires Python 2.5 to be installed
Blender 2.49 requires Python 2.6[n]
Open Blender 2.5[n] (shown below) and the console informs the user that its currently using a set of bundled Python files - note: this may change for future versions within the 2.5x series.
Blender 2.5[n] can use it's own internal Python modules