The Infamous Environment Variable Issue!!

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
thru2trot
Posts: 0
Joined: Sat May 15, 2010 7:19 pm

The Infamous Environment Variable Issue!!

Post by thru2trot » Thu Jan 13, 2011 1:25 am

Hello Blender Collective,

Well I've officially given up on trying to fix my python paths, but here are my findings. I must have broken my blender install as it relates to coding and launching blender in context of python3.1 from Ubuntu's version 10.10 (Maverick). First off, if it gives you guys any inclination I am trying to run Komodo and other IDE's in context of Blender.. In a tutorial that I found on-line with other people that were having the same problem, I found that first off, a lot of users claim that the the profile and profile.d(located in /etc/)are the files that I should be concerned with, in terms of setting environment variables for python. There instructions, which are primarily a culmination of a lot of writings explained that the first thing I should do is launch python in the linux Terminal:

So, in lieu to this, after running:

unset PYTHONHOME
unset PYTHONPATH

( Of course, If I don't do this, I get this:
myname@mysystem:~$ python
'import site' failed; use -v for traceback
ActivePython 2.6.6.17 (ActiveState Software Inc.) based on
Python 2.6.6 (r266:84292, Nov 23 2010, 18:36:13)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
)

I type python in the Terminal after unsetting PYTHONHOME and PYTHONPATH and I get this:

(myname@mysystem:~$ python
ActivePython 2.6.6.17 (ActiveState Software Inc.) based on
Python 2.6.6 (r266:84292, Nov 23 2010, 18:36:13)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>)

So as you can see, I no longer get the error that I received above.

After this the tutorial says to type python, then:
>>> import sys
>>> print sys.path

,which gives me this:

['', '/opt/ActivePython-2.6/lib/python26.zip', '/opt/ActivePython-2.6/lib/python2.6', '/opt/ActivePython-2.6/lib/python2.6/plat-linux2', '/opt/ActivePython-2.6/lib/python2.6/lib-tk', '/opt/ActivePython-2.6/lib/python2.6/lib-old', '/opt/ActivePython-2.6/lib/python2.6/lib-dynload', '/opt/ActivePython-2.6/lib/python2.6/site-packages', '/opt/ActivePython-2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']

I then try and copy this info to my .bashrc file in my home directory and nothing happens, and of course I edit it so its in the correct syntax in my .bashrc file which then looks like this:

PYTHONPATH=/opt/ActivePython-2.6/lib/python26.zip;/opt/ActivePython-2.6/lib/python2.6;/opt/ActivePython-2.6/lib/python2.6/plat-linux2;/opt/ActivePython-2.6/lib/python2.6/lib-tk;/opt/ActivePython-2.6/lib/python2.6/lib-old;/opt/ActivePython-2.6/lib/python2.6/lib-dynload;/opt/ActivePython-2.6/lib/python2.6/site-packages;/opt/ActivePython-2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info

And, this still does not work. One things for certain, however, the profile file, located in /etc did contain /usr/lib64/python2.6 as PYTHONPATH, which is exactly what I got prior to installing ActiveState's version of python 3.1(which seems to have conflicted with my working system python3 install. Again, this is a huge learning process for me and I thank you for all your help. Thanks so much for all your help. I can't wait to really start coding.

Best Regards,

thru2trot

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Thu Jan 13, 2011 3:26 am

I don’t understand. Why would you be having an ActiveState Python build on your Linux system? Ubuntu should be using something derived from the Debian build.

thru2trot
Posts: 0
Joined: Sat May 15, 2010 7:19 pm

Post by thru2trot » Thu Jan 13, 2011 3:29 am

Thanks for the reply Ido,

I'm using it because I'm using Komodo IDE 6.0.3. I'm sure I didn't need to use it but it just seems o make things easy as it relates to learning python in context of finding preconfigured modules!!

Best Regards,

thru2trot

thru2trot
Posts: 0
Joined: Sat May 15, 2010 7:19 pm

Post by thru2trot » Thu Jan 13, 2011 3:34 am

Now this is the error that I get in the Terminal when I launch blender2.56a:

myname@mycomputer:~$ blender
found bundled python: /home/myname/source/blender-2.56a-beta-linux-glibc27-i686/2.56/python
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "/usr/lib/python2.6/encodings/utf_8.py", line 9, in <module>
File "/usr/lib/python2.6/codecs.py", line 16
except ImportError, why:
^
SyntaxError: invalid syntax
Aborted
myname@mycomputer:~$

Of course, this version of blender only works with python3.1 and for some odd reason my environment variables keep pointing to python2.6. Again thanks for the reply, any help would be greatly appreciated.

Best Regards,

thru2trot

thru2trot
Posts: 0
Joined: Sat May 15, 2010 7:19 pm

Post by thru2trot » Thu Jan 13, 2011 5:37 am

For whatever reason, the profile file located in /etc/ is what was breaking the installation. Once I went in and erased this portion the code, which is located at the end of the file, that seemed to have taken care of everything:

This is what I erased:

PATH="$PATH:/opt/blender"
export PATH

if [ -x /usr/bin/python ]; then
PYTHONPATH=/usr/lib/python2.6:/usr/lib/python2.7:/usr/lib/python2.6/dist-packages:/opt/ActiveTcl-8.4:/opt/ActiveTcl-8.5:/usr/lib/python3.1/tkinter:/usr/lib/tk8.4:/usr/lib/tk8.5:/opt/py31:/opt/py31/bin
PYTHONHOME=$PYTHONPATH
export PYTHONPATH PYTHONHOME
fi

if [ -x /usr/bin/python ]; then
PYTHONOPTIMIZE=true
export PYTHONOPTIMIZE
fi

What this does, I have no idea, but it sure did cause me a lot of grief.

Best Regards,

thru2trot

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Thu Jan 13, 2011 6:22 am

a couple points that may help clear some of this up:

Blender does NOT use the system Python interpreter. Blender has Python built-in. If you are using an IDE, you are running a different Python interpreter.

In most cases, you do NOT need to set environment variables unless you have installed Python in a strange place. Setting env vars incorrectly is a quick way to break things.

For Blender 2.4x and lower: you must install the (major) version of Python that Blender was built against. For reasonably up to date distros, this is Python 2.6. Install the highest minor version you can find. (last I looked, it was 2.6.6

Blender 2.5x comes with the correct version of Python (3.1). You do not need to install it.

Do not mix Python 2.x and Python 3 in your paths.

thru2trot
Posts: 0
Joined: Sat May 15, 2010 7:19 pm

Post by thru2trot » Thu Jan 13, 2011 7:31 am

Thanks much for the explanation stiv,

Well, I am trying to learn how to script. So here goes, in lieu to all of this, in the interactive console in the latest blender 2.56a, I am trying to run this:

Code: Select all

#!BPY

import Blender
from Blender import Scene, Text3d, Window

hello = Text3d.New("HelloWorld")
hello.setText("Hello World")


scn = Scene.GetCurrent()
ob = scn.objects.new(hello)


Window.RedrawAll()
and I keep getting these as errors:

(Traceback most recent calls last)
Import Error(No module named blender)
location:<unknown location>:-1
Python script failed, look in the console for now

Don't know if this is a path issue!!

Best Regards,

thru2trot

ldo
Posts: 0
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Fri Jan 21, 2011 9:44 am

Blender most certainly does use the system Python itnerpreter. Remember, this is Linux we’re talking about, not Windows.

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Fri Jan 21, 2011 7:05 pm

Don't know if this is a path issue!!
The issue here is that 2.5x has a completely different Python interface (the API - Application Programming Interface). Old scripts DO NOT work. They must be converted to use the new API.

For examples, see the templates in the Text Editor window and the 2.5x API Docs on the Blender Wiki. The Add-Ons are also interesting.

taylah
Posts: 0
Joined: Mon Oct 24, 2011 11:36 am

Post by taylah » Mon Oct 24, 2011 11:41 am

I actually fixed this partially. The system python2.6, and python2.7 works. However when I type python3 or python3.1 in my Terminal, I get this:

myname@mycomputer:~$ python3
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "/usr/lib/python2.6/encodings/utf_8.py", line 9, in <module>
Aborted

For whatever reason, the system still seems to be pointing to Python2.6, which is the installed version that came with Ubuntu10.10(Maverick)!! My Komodo install seems to have broken it. Any help on this would be greatly appreciated guys, I can't wait to start programming and using Blender!!

Best Regards, taylah

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Mon Oct 24, 2011 7:31 pm

myname@mycomputer:~$ python3
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "/usr/lib/python2.6/
OK, let's run thru this again:

New Blender (2.5x and above) comes with its own version of Python (Py 3.2 at the moment). You can have whatever version you want of Python installed on your system. ( Note: to build blender with scons, you need py 2.6 or so)

Hard to tell what you have done, but you are trying to run python3 and getting "/usr/lib/python2.6/..." stuff. The easiest way to do this wrong is to set environment variables incorrectly.

If you want python3 on your system for whatever reason, install it and do not mess with the environment variables. Different versions of Python will happily live together and find their own libraries if you do not try to be tricky.

Post Reply