Python import from collections fails

I want to use Counter (https://pymotw.com/2/collections/counter.html).
Why doesn’t it work?

import clr
import System
clr.AddReference("System.Core")
from System.Collections import Counter

Cannot import name Counter

from System.Collections import Counter as testingtesting
Same error

Collections is not a .NET library. It’s a Python library. Just do this:

2 Likes

ok, good to know,

still getting an error. Using dynamo 1.3 which should matter right (both using python 2.7)

image

Never mind, added the path to the lib.

sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
2 Likes

The reason you had to add it is that for Dynamo 2.0+ that IronPython 2.7 is actually shipped with Dynamo as opposed to Dynamo 1.3 where it was installed alongside of Dynamo. Any libraries we would want to reference from python’s lib folder, we had to add that location to the references like you did above. Just FYI.

2 Likes