0

I'm trying to use the itertools module to use the permutations function but I'm having problems with my Mac.

I've been programing on another computer using linux and have no problem to use the code.

import itertools
ps = itertools.permutations(m)

This is the error I'm getting when I'm working on a Mac:

AttributeError: 'module' object has no attribute 'permutations'

Anyone knows how can I use 'itertools' in Mac?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
user981227
  • 155
  • 2
  • 6
  • 12

3 Answers3

2

You're probably running python 2.5, which has no permutations. It's new in 2.6.

You can find a python implementation of permutations you can use for 2.5 code in the python docs: http://docs.python.org/library/itertools.html#itertools.permutations

Adam Wagner
  • 15,469
  • 7
  • 52
  • 66
  • It's worth noting that some of the "equivalent to" code is _not actually equivalent_. See for example [this question about the `izip_longest` Python implementation](http://stackoverflow.com/questions/7392902/izip-longest-in-itertools-how-does-rasing-indexerror-inside-the-iterator-work/7393480#7393480). You might be better off using the PyPy implementation, which is probably a fairly straightforward reimplementation of the C version in RPython. – agf Oct 30 '11 at 15:48
  • @agf: I'll keep that in mind.. I've not looked too closely into these "equivalent implementations." – Adam Wagner Oct 30 '11 at 15:50
  • For permutations(), the pure python equivalent is algorithmically equivalent -- the C version was a direct translation but substituted C for-loops for Python's range() and reversed(); otherwise, the code is essentially the same. – Raymond Hettinger Oct 30 '11 at 17:04
1

The documentation says New in version 2.6., so you might be running an older version. At least on my OSX Lion (Python 2.7.1) from itertools import permutations works.

Kimvais
  • 38,306
  • 16
  • 108
  • 142
0

A typical library linker problem. A very useful guide for this problem(you should update the the linkages to python 2.6 and later -for system wide or just in IDE-) with additional tips, can be found here