我正在运行 ubuntu 14.04 并尝试启动 ROS 模拟器。我有这个错误:
ImportError: No module named 'glob'
安装 glob2 并不能解决问题。
python -m site
输出:
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
对于Python 2.7:
pip install glob2
对于Python 3.7:
pip3 install glob2
对于 Python 3,没有
glob3
。
所以使用:
sudo pip3 install glob2
ROS本来就不支持Python 3,所以我不建议你使用它。您应该安装 2.7。
重新下载:https://www.python.org/downloads/
这是 glob 的来源:https://docs.python.org/2/library/glob.html
如您所见,它位于 Lib 包中,将其标记为标准
在Python 3.10版本中,glob模块包含在标准模块列表中。这意味着您不需要安装它。
您可能会遇到此错误,因为您正在使用任何早期版本的 python。
在这种情况下使用
pip3 install glob2
但请确保您必须使用
导入它import glob
# not import glob2
希望这有帮助。
快乐的通配符。
pip3 install glob2
然后刷新
基本上。
如果您指的是 Python 中的“全局模块”,则您可能指的是可在整个程序中访问的模块,而不是仅限于特定范围或函数。在 Python 中,您可以通过在脚本或模块的顶层定义变量、函数或类来创建全局模块。
以下是如何在模块中定义全局变量的示例:
# 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.")
在上面的示例中,
global_var
、my_function()
和MyClass
都可以在整个模块中访问,并且可以在程序的其他部分导入和使用。
要使用模块中定义的全局变量、函数或类,您可以使用
import
语句将模块导入到脚本或其他模块中:
# 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.
通过导入
mymodule
,您可以访问和使用其中定义的全局实体。
我希望这有帮助!如果您还有任何疑问,请告诉我。
如果您使用 Linux 发行版,请编写以下命令:
sudo pip install glob2
对于Python 3:
sudo pip3 install glob2
如果您使用 Windows: 打开命令提示符并写入以下命令:
pip install glob2
对于Python 3:
pip3 install glob