ModuleNotFoundError:没有名为“ folium.plugins”的模块; 'folium'不是包装

时间:2019-01-04 15:11:32

标签: python folium

我知道这个问题已经问了好几次了,但是到目前为止,没有一种解决方案可以帮助我。

每当我尝试运行python脚本时,都会出现以下错误:

M-MBP:folder m$ python3.7 folium.py
Traceback (most recent call last):
  File "folium.py", line 3, in <module>
    import folium
  File "/Users/m/folder/folium.py", line 4, in <module>
    from folium.plugins import MarkerCluster
ModuleNotFoundError: No module named 'folium.plugins'; 'folium' is not a package

注意:

  • 我正在运行通过 Homebrew 安装的Python3.7;
  • 我尝试通过 pip conda 安装Folium,并直接将其Git存储库克隆到我的站点软件包文件夹中。
  • li>

没有一个工作。有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您的脚本的名称与所需的软件包相同。它正在尝试自行导入,并且其中没有plugins。将脚本命名为folium.py以外的其他名称,我相信您的问题将会消失。

已展示:

arts@support:~ 0$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.DEBUG
10
>>>
arts@support:~ 0$ cd tmp
arts@support:~/tmp 0$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/arts/tmp/logging.py", line 5, in <module>
    print(logging.DEBUG)
AttributeError: 'module' object has no attribute 'DEBUG'
>>>
arts@support:~/tmp 0$ cat logging.py
import sys
import logging    # Imports itself
import os

print(logging.DEBUG)

原因是,您需要查看sys.path

arts@support:~/tmp 0$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib64/python34.zip', '/usr/lib64/python3.4', '/usr/lib64/python3.4/plat-linux', '/usr/lib64/python3.4/lib-dynload', '/usr/lib64/python3.4/site-packages', '/usr/lib/python3.4/site-packages']
>>> del sys.path[0]
>>> sys.path
['/usr/lib64/python34.zip', '/usr/lib64/python3.4', '/usr/lib64/python3.4/plat-linux', '/usr/lib64/python3.4/lib-dynload', '/usr/lib64/python3.4/site-packages', '/usr/lib/python3.4/site-packages']
>>> import logging
>>> logging.DEBUG
10
>>>
arts@support:~/tmp 0$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib64/python34.zip', '/usr/lib64/python3.4', '/usr/lib64/python3.4/plat-linux', '/usr/lib64/python3.4/lib-dynload', '/usr/lib64/python3.4/site-packages', '/usr/lib/python3.4/site-packages']
>>> import logging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/arts/tmp/logging.py", line 5, in <module>
    print(logging.DEBUG)
AttributeError: 'module' object has no attribute 'DEBUG'
>>>

在第二个块中,您将看到我删除了列表的第一个块。这样会从python的导入路径中删除您的CURRENT DIRECTORY,因此它现在忽略了我的logging.py文件并成功导入了真实的logging模块。