0

I know this question has been asked around quite a few times but none of the solutions have helped me out so far.

I am getting the following error whenever I try running my python script:

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

Notes:

  • I am running Python3.7, installed via Homebrew;
  • I've tried installing Folium via pip, conda, and cloning its Git repo directly to my site-packages folder.

None have worked. Any suggestions?

Thanks!

UtahJarhead
  • 2,091
  • 1
  • 14
  • 21
Arturo Belano
  • 113
  • 2
  • 9

1 Answers1

0

Your script is named the same as the package you want. It's trying to import itself and it doesn't have plugins within it. Name your script something other than folium.py and I believe your problem will disappear.

Demonstrated:

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)

The reason is, you need to look at 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'
>>>

In this second chunk, you'll see that I deleted the first chunk of the list. This removes your CURRENT DIRECTORY from python's import path, so it now ignored my logging.py file and successfully imported the real logging module.

UtahJarhead
  • 2,091
  • 1
  • 14
  • 21