Attempts to import the site module are met with a TypeError exception. #29635

Closed
opened 2011-12-15 22:30:44 +01:00 by Sam Bushman · 3 comments

%%%Operating System: Windows 7 32-Bit
Video Card: ATI Radeon HD 5450 with catalyst version 11.11
Blender 2.61 Windows binary

When running a python script or executing lines in the python console, if I attempt to import the site module (done by executing the line "import site") the following error message is displayed by the interpreter:
Traceback (most recent call last):

File "<blender_console>", line 1, in <module>
File "C:\Users\User\Desktop\blender-2.61-release-windows32\2.61\python\lib\site.py", line 529, in <module>
  main()
File "C:\Users\User\Desktop\blender-2.61-release-windows32\2.61\python\lib\site.py", line 513, in main
  abs_paths()
File "C:\Users\User\Desktop\blender-2.61-release-windows32\2.61\python\lib\site.py", line 84, in abs_paths
  for m in set(sys.modules.values()):

TypeError: unhashable type: 'list'

It seems that some of the values contained in the dict_values construct returned by sys.modules.values() cannot be added to a set. When comparing the types of objects contained in the dict_values construct between Blender 2.60 and 2.61 there were two new types in the 2.61 version:
<class 'bpy.app.handlers'>
<class 'bpy.app'>

It is my hypothesis that when either of the two objects in the dict_values list that are of these types are being added to the set, the exception is thrown. As a temporary work around, I explicitly make the set by iterating through the list returned by sys.modules.values(), adding each element to a temporary set one at a time. I surround the addition of each element with a try/except block to prevent erroneous objects from being added. A sample is below:
BEFORE:
for m in set(sys.modules.values()):

      if hasattr(m, '__loader__'):
          continue   # don't mess with a PEP 302-supplied __file__
      try:
          m.__file__ = os.path.abspath(m.__file__)
      except (AttributeError, OSError):
          pass
      try:
          m.__cached__ = os.path.abspath(m.__cached__)
      except (AttributeError, OSError):
          pass

AFTER:

  tmpSet = set()
  for foo in sys.modules.values():
      try:
          tmpSet.add(foo)
      except:
          pass
  for m in tmpSet:
      if hasattr(m, '__loader__'):
          continue   # don't mess with a PEP 302-supplied __file__
      try:
          m.__file__ = os.path.abspath(m.__file__)
      except (AttributeError, OSError):
          pass
      try:
          m.__cached__ = os.path.abspath(m.__cached__)
      except (AttributeError, OSError):
          pass%%%
%%%Operating System: Windows 7 32-Bit Video Card: ATI Radeon HD 5450 with catalyst version 11.11 Blender 2.61 Windows binary When running a python script or executing lines in the python console, if I attempt to import the site module (done by executing the line "import site") the following error message is displayed by the interpreter: Traceback (most recent call last): ``` File "<blender_console>", line 1, in <module> File "C:\Users\User\Desktop\blender-2.61-release-windows32\2.61\python\lib\site.py", line 529, in <module> main() File "C:\Users\User\Desktop\blender-2.61-release-windows32\2.61\python\lib\site.py", line 513, in main abs_paths() File "C:\Users\User\Desktop\blender-2.61-release-windows32\2.61\python\lib\site.py", line 84, in abs_paths for m in set(sys.modules.values()): ``` TypeError: unhashable type: 'list' It seems that some of the values contained in the dict_values construct returned by sys.modules.values() cannot be added to a set. When comparing the types of objects contained in the dict_values construct between Blender 2.60 and 2.61 there were two new types in the 2.61 version: <class 'bpy.app.handlers'> <class 'bpy.app'> It is my hypothesis that when either of the two objects in the dict_values list that are of these types are being added to the set, the exception is thrown. As a temporary work around, I explicitly make the set by iterating through the list returned by sys.modules.values(), adding each element to a temporary set one at a time. I surround the addition of each element with a try/except block to prevent erroneous objects from being added. A sample is below: BEFORE: for m in set(sys.modules.values()): ``` if hasattr(m, '__loader__'): continue # don't mess with a PEP 302-supplied __file__ try: m.__file__ = os.path.abspath(m.__file__) except (AttributeError, OSError): pass try: m.__cached__ = os.path.abspath(m.__cached__) except (AttributeError, OSError): pass ``` AFTER: ``` tmpSet = set() for foo in sys.modules.values(): try: tmpSet.add(foo) except: pass for m in tmpSet: if hasattr(m, '__loader__'): continue # don't mess with a PEP 302-supplied __file__ try: m.__file__ = os.path.abspath(m.__file__) except (AttributeError, OSError): pass try: m.__cached__ = os.path.abspath(m.__cached__) except (AttributeError, OSError): pass%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'

%%%fixed r42657.%%%

%%%fixed r42657.%%%

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#29635
No description provided.