11

I am working with Eclipse Kepler(2013) and python 3.3.2 and running a simple import like

import glob
a = glob.glob('*')
print(a)

gives a:

TypeError: 'module' object is not callable

This is not the case if I run the same code in Idle. I know I am missing something.

Any help is appreciated.

3
  • 1
    What does glob.__file__ returns? Sep 6, 2013 at 12:02
  • Never use the same name of a built-in module or function.
    – Bakuriu
    Sep 6, 2013 at 16:19
  • It is mentioned in one answer below, but the solution is very simple: use import glob as glob
    – mikey
    Aug 7, 2020 at 15:55

5 Answers 5

22

What worked for me was i changed import glob to from glob import glob at the top of the file.

1
  • 4
    This is the best answer here
    – mikey
    Aug 7, 2020 at 15:54
8

In some cases people end up using same file name as built in modules. Don't name your file as "glob.py".

1
  • 2
    Thanks! that was it. Also, if you have a left-over glob.pyc file that got created from your glob.py - clean it too...
    – arielf
    Sep 11, 2017 at 20:27
6

Probably in your Eclipse environment there's a module named glob that gets imported before the standard library one.

Try printing the glob.__file__ to check it out.

1
  • THis comment helped understanding the problem. Grazie Paolo!
    – rearThing
    Sep 7, 2013 at 7:42
4

This is only possible if you've defined a package named glob in the module search path, so instead of loading the built-in module glob python is importing that package.

Something like this in the module search path

glob
├── glob.py
├── glob.pyc
├── __init__.py
└── __init__.pyc

will produce the same error:

>>> import glob
>>> glob.__file__
'/home/monty/py/glob/__init__.pyc'
>>> glob.glob()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

You need to change the name of this package to something else because it seems to be present on the module search path used by eclipse.

1
  • 2
    LOL. I named my python script 'glob.py' and wondered why I couldn't access the glob module.
    – downeyt
    Jul 18, 2015 at 18:53
0

I changed import glob to from glob import glob. It works fine for me. You can try it

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jun 8, 2022 at 4:33

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.