Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to NumPy Array Organization Manipulation

Charles Willden
Charles Willden
12,357 Points

np.lookfor("flat") returns TypeError: 'NoneType' object is not iterable

NumPy's lookfor() is not working for me. Any ideas?

np.lookfor("flat")

Returns:

TypeError Traceback (most recent call last) <ipython-input-90-086329ed8c81> in <module> ----> 1 np.lookfor("flat")

~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\utils.py in lookfor(what, module, import_modules, regenerate, output) 749 750 # Cache --> 751 cache = _lookfor_generate_cache(module, import_modules, regenerate) 752 753 # Search

~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\utils.py in lookfor_generate_cache(module, import_modules, regenerate) 901 # import sub-packages 902 if import_modules and hasattr(item, 'path'): --> 903 for pth in item.path_: 904 for mod_path in os.listdir(pth): 905 this_py = os.path.join(pth, mod_path)

TypeError: 'NoneType' object is not iterable

2 Answers

I get the same. But if I then run np.lookfor("flat") a second time the result displays as it should.

Charles Willden
Charles Willden
12,357 Points

KRIS NIKOLAISEN , thanks that is helpful. I had not attempted that, but it works for me as well.

Is it possible your installation is messed up in some way? Perhaps you are using an obsolete version of numpy, or one that is intended for a different version of python than what you have?

Assuming this is on your own system, why not start by reinstalling python and numpy?

Charles Willden
Charles Willden
12,357 Points

Not likely. I'm running a completely fresh install of latest version of Anaconda. Also verified NumPy is up to date (1.16.4)