0

I have Blender 2.66a which is an application that offers Python 3.3 APIs, On my system I have an installation of Python 3.2 with several modules that I wish to use inside Blender, I tried both

sys.path.append(r"/usr/lib/python3.2/")
sys.path.append("/usr/lib/python3.2/")

and this commands gives no errors, infact even the autocomplete feature works and new modules are indexed, so i tried

import tkinter

but this generates the following error

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/usr/lib/python3.2/tkinter/__init__.py", line 42, in <module>
    raise ImportError(str(msg) + ', please install the python-tk package')
ImportError: No module named '_tkinter', please install the python-tk package

and I don't get the point of this error because it fails to load a module that it's there asking me to install the same module because that module is not installed ( ? ).

What can cause this obscure problem ?


EDIT

the tkinter module works from the gnome-terminal

6
  • This has nothing to do with sys.path.append not working. You are missing a library the C parts of tkinter need to work. Commented Apr 8, 2013 at 18:30
  • @Wooble what library? tkinter works from the regular console, also other modules can be imported without errors from that path Commented Apr 8, 2013 at 18:31
  • Did you check the version of python in the console and in the Blender modules? They are probably different, and the python-tk package is probably installed only for a specific version. Commented Apr 8, 2013 at 18:52
  • @Bakuriu as stated in the post, 3.2 for the python os installation ( where tkinter comes from ) and 3.3 for Blender APIs ( where I'm trying to retrieve tkinter as module ); I'm not sure if this is a real problem by the way, it's always python 3.x Commented Apr 8, 2013 at 18:55
  • 1
    Did you try to add /usr/lib/python3.2/lib-dynload to the path? that's where the _tkinter modules lives on linux(at least my machine). Anyway, as explained by delnan I don't think it will work. Commented Apr 8, 2013 at 19:06

1 Answer 1

3

If I got you right, you're using Python 3.3 from Blender but try to include the 3.2 standard library. This is bound to give you a flurry of issues, you should not do that. Find another way. It's likely that Blender offers a way to use the 3.3 standard library (and that's 99% compatible with 3.2). Pure-Python third party library can, of course, be included by fiddling with sys.path.

The specific issue you're seeing now is likely caused by the version difference. As people have pointed out in the comments, Python 3.3 doesn't find the _tkinter extension module. Although it is present (as it works from Python 3.2), it is most likely in a .so file with an ABI tag that is incompatible with Blender's Python 3.3, hence it won't even look at it (much like a module.txt is not considered for import module). This is a good thing. Extension modules are highly version-specific, slight ABI mismatches (such as between 3.2 and 3.3, or two 3.3 compiled with different options) can cause pretty much any kind of error, from crashes to memory leaks to silent data corruption or even something completely different.

You can verify whether this is the case via import _tkinter; print(_tkinter.__file__) in the 3.2 shell. Alternatively, _tkinter may live in a different directory entirely. Adding that directory won't actually fix the real issue outlined above.

Sign up to request clarification or add additional context in comments.

1 Comment

apparently _tkinter lives under /usr/lib/python3.2/lib-dynload/ but appending this path to the sys.path doesn't solve anything, I think that this 2 Python version are not compatible in the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.