I see that I’m repeating a lot here, but here it goes anyway, you can never read this enough times
First, despite that python by now has moved on to version 2.2, Blender currently is still based on python2.01. It is possible to use higher python versions, but if you want full compatibilty, you have to install python2.01.
UPDATE:
As of Blender version 2.26 (as well as ‘funblender’) this is no longer true, which were compiled with python2.2, so for these it is best to install python2.2, NOT python2.01.
WINDOWS
- Get python2.0 from http://www.python.org/2.0.1/
Direct link to the installer(might not work, you might have to use the above link instead):
http://www.python.org/ftp/python/2.0.1/Python-2.0.1.exe
To make sure that python when run from Blender can find the files it needs, you need to set a so-called ‘environment variable’ which contains all the directories python needs to be able to run properly.
-
PYTHON LIB SHORTCUT:
There is a shortcut to do this, which will make it possible to run most scripts, but not all of them, so it is better to set the PYTHONPATH variable, but if you don’t want to do that, you can try this. If you want to set the full pythonpath, skip ahead to part 3.
It is possible to specify the most important python directory in Blender itself, you do that by specifying this in the user-defaults window, this window is hidden away at the top of the main Blender window.
Drag the header downwards to find it, you can also use the windows icon, then selecting the ‘i’ icon (info-window).
On the left side you will find a button with the name ‘Python:’, click that, and type the full path to the python lib directory, use the path to wherever you installed python, for me it would be:
c:\python20\lib
followed by enter, drag the window back (otherwise Blender will always start with this window open), and use CTRL-U key (save user-defaults) and confirm by clicking or using the enterkey to save your settings.
That is all, this will be enough for most scripts.
-
FULL PYTHONPATH:
After installing python and restarting your computer, you will find a new menu entry in the windows ‘Start’ menu, there is an option called ‘python(commandline)’, select that, and python will start in a dos-console printing something like this on the screen:
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>>
The reason for doing this is to find out what directories to add to your PYTHONPATH variable. To do this, type ‘import sys’ followed by enter. Then ‘print sys.path’, the result should look something like this:
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', 'c:\\python20', 'c:\\python20\\dlls', 'c:\\python20\\lib', 'c:\\python20\\lib\\plat-win', 'c:\\python20\\lib\\lib-tk', 'c:\\python20\\pil']
This is what I get, for you it might be different of course, depending on where you installed python. The important directories are the main directory, the ‘dlls’ directory, and the ‘lib’ and ‘lib-tk’ directories.
Any other ones you don’t need to add to the environment variable, but you can do that anyway if you want.
Now we need to create an environment variable that contains the same directories.
(btw, To close the python console use ‘ctrl-z’)
This will depend on what windows version you use, for Win98 for instance you have to add this variable to your autoexec.bat
Open it with notepad for instance, and add the line ‘SET PYTHONPATH=’ plus the important directories that python printed in the console window as above. So for me it would look like this:
SET PYTHONPATH=C:\PYTHON20;C:\PYTHON20\DLLS;C:\PYTHON20\LIB;C:\PYTHON20\LIB\LIB-TK
Save it, restart your computer, and that should be it.
To set environment variable on Win2000 or WinXP, see the post by Enzoblue or theeth above.
LINUX
Most if not all distributions already include a version of python, if not, you will have to compile and install it
yourself. As this is not unusual for Linux users, I won’t repeat the steps here.
- To find out what you have to add to your pythonpath, open a shell/terminal and start python (type python or python2.0).
Then type ‘import sys’ followed by ‘print sys.path’, which will produce something like this:
Python 2.0.1 (#5, Jun 21 2002, 22:51:17)
[GCC 2.95.3 20010315 (SuSE)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/local/lib/python2.0', '/usr/local/lib/python2.0/plat-linux2', '/usr/local/lib/python2.0/lib-tk', '/usr/local/lib/python2.0/lib-dynload', '/usr/local/lib/python2.0/site-packages']
- There are now several posibilities to add the pythonpath environment variable, depending on what you use, for bash you can add this to your .bashrc file which you will find in your home directory. Open it with an editor and add the following line:
export PYTHONPATH=/usr/local/lib/python2.0:/usr/local/lib/python2.0/plat-linux2:/usr/local/lib/python2.0/lib-tk:/usr/local/lib/python2.0/lib-dynload:/usr/local/lib/python2.0/site-packages
(I’m not entirely sure about this next bit as for me it is the above)
In case you use a tcsh based shell, you need to add this to .cshrc, in which case it is slightly different:
setenv PYTHONPATH /usr/local/lib/python2.0:/usr/local/lib/python2.0/plat-linux2:/usr/local/lib/python2.0/lib-tk:/usr/local/lib/python2.0/lib-dynload:/usr/local/lib/python2.0/site-packages
I have found other references on the net that another possibility is adding it to /etc/profile.d, but I’m not a Linux expert, so I can’t say much about that.
After you set the pythonpath, log out and back in again to make it active.
For both platforms, a link that might be helpful:
http://www.janw.gothere.uk.com/pythoninstall.html