Nameerror: Name 'Glob' Is Not Defined
#coding=utf 
import glob
glob.glob('/pycharm/*') 

I used to the python3.5 version , TypeError: 'module' object is not callable

#coding=utf
from glob import *
glob('/pycharm/*')

It has another error, NameError: name 'glob' is not defined

7

5 Answers

If you just need glob() makes sure that the function name is the same as a module name. This worked for me.

from glob import glob
g = glob('*.jpg')

Please check if "glob" is used as a variable in the code, before the import statement is called.

if "glob" is used as a variable, the original meaning of the module will change, giving the mentioned errors.

1

You just need to install the glob module in your machine by the following command $ pip install glob2

and after the installation, you just need to do the following changes in your code

import glob2

g = glob2.glob('/pycharm/*')

Or you can import only the glob module from the glob2 for the better performance

from glob2 import glob
g = glob2.glob('/pycharm/*')

If you can import this package in terminal, maybe you should check if you import glob before call it or not.I met this error today in a jupyter notebook, find I forget to run the import sentence XD

you need to add full path like this

import glob
covid_path = r'C:\Users\Mohmed\Desktop\Corona Project\new start\CNN\CT_COVID'
covid_files = glob.glob(covid_path + '/*')
print(len(covid_files))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest