17

I am running ubuntu 14.04 and trying to launch ROS Simulator. I have this error:

ImportError: No module named 'glob'

Installing glob2 does not solve the problem.

python -m site output:

sys.path = [
    '/home/omar',
    '/opt/ros/indigo/lib/python2.7/dist-packages',
    '/home/omar/anaconda3/lib/python35.zip',
    '/home/omar/anaconda3/lib/python3.5',
    '/home/omar/anaconda3/lib/python3.5/plat-linux',
    '/home/omar/anaconda3/lib/python3.5/lib-dynload',
    '/home/omar/anaconda3/lib/python3.5/site-packages',
    '/home/omar/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg',
    '/home/omar/anaconda3/lib/python3.5/site-packages/numba-0.29.0-py3.5-linux-x86_64.egg',
    '/home/omar/anaconda3/lib/python3.5/site-packages/glob2-0.4.1-py3.5.egg',
    '/home/omar/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg',
]
USER_BASE: '/home/omar/.local' (exists)
USER_SITE: '/home/omar/.local/lib/python3.5/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
martineau
  • 119,623
  • 25
  • 170
  • 301
Omar Amr
  • 403
  • 1
  • 5
  • 10

6 Answers6

32

For python 2.7:

pip install glob2

For python 3.7:

pip3 install glob2

Community
  • 1
  • 1
Ishan Khatri
  • 555
  • 5
  • 10
  • 7
    You really shouldn't sudo install packages for security purposes. – Skyler Wiernik Apr 21 '20 at 23:46
  • 6
    even for pip3 it's still glob2, not glob3 :-D – J. Tylka Jan 08 '21 at 00:13
  • @SkylerWiernik what are the security concerns of using sudo for installation? – PJ_ Jul 12 '21 at 13:36
  • 2
    @PedroMartinez you are giving the installation scripts of the package you are installing route access. If you were to install a malicious package (through something such as a type-o) you could potentially give hackers full access to your entire machine. – Skyler Wiernik Jul 30 '21 at 23:55
5

For Python 3, there is no glob3.

So use:

sudo pip3 install glob2
Tonechas
  • 13,398
  • 16
  • 46
  • 80
H.A. R
  • 69
  • 1
  • 2
  • 4
    You *should* not do sudo pip install. `pip3 install package_name` works fine. –  Jun 04 '21 at 07:51
2

In Python version 3.10, the glob module is included in the standard module list. It means you do not need to install it.

You might be facing this error because you are using any prior version of python.

In this case use

pip3 install glob2

But make sure you have to import it using

import glob 
# not import glob2

Hope this helped.

Happy Globbing.

AlixaProDev
  • 472
  • 1
  • 5
  • 13
0

ROS does not support Python 3 in the first place, so I would not recommend you use it. You should install 2.7.

Redownload it: https://www.python.org/downloads/

Here's the source for glob: https://docs.python.org/2/library/glob.html

As you can see it's in the Lib package which marks it as standard

cjds
  • 8,268
  • 10
  • 49
  • 84
0

pip3 install glob2 and then refresh it basically. If you're referring to a "global module" in Python, it's possible you're referring to a module that is accessible throughout your entire program, rather than being limited to a specific scope or function. In Python, you can create global modules by defining variables, functions, or classes at the top level of your script or module.

Here's an example of how you can define a global variable in a module:

# mymodule.py

global_var = 10

def my_function():
    print("This is a global function.")

class MyClass:
    def __init__(self):
        print("This is a global class.")

In the above example, global_var, my_function(), and MyClass are all accessible throughout the module and can be imported and used in other parts of your program.

To use the global variables, functions, or classes defined in your module, you can import the module into your script or another module using the import statement:

# main.py

import mymodule

print(mymodule.global_var)  # Output: 10

mymodule.my_function()  # Output: This is a global function.

obj = mymodule.MyClass()  # Output: This is a global class.

By importing the mymodule, you can access and utilize the global entities defined within it.

I hope this helps! Let me know if you have any further questions.

ShadowCrafter_01
  • 533
  • 4
  • 19
-1

if you use Linux Distributions write this command:

sudo pip install glob2

for python 3:

sudo pip3 install glob2 

and if you using Windows: open a command prompt and write this command:

pip install glob2

for python 3:

pip3 install glob
JavadMH13
  • 33
  • 1
  • 8