No module named 'folium' after installing via pip

Question:

Basically after I have already installed folium with pip (pip install folium)
previously the code worked, but suddenly I got this error.

Here is my code:

import pandas as pd
import folium
from geopy.geocoders import ArcGIS

#data frame
snifim_df = pd.read_csv('Snif.csv')
nom = ArcGIS()

snifim_df['LAT'] = snifim_df['Address'].apply(nom.geocode,timeout=15).apply(lambda x:x.latitude)
snifim_df['LON'] = snifim_df['Address'].apply(nom.geocode,timeout=15).apply(lambda x:x.longitude)


Mcmap = folium.Map(location=[32.58, -99.09], zoom_start = 6)
fg = folium.FeatureGroup(name = "McDonalds")

snif_lat = list(snifim_df['LAT'])
snif_lon = list(snifim_df['LON'])
snif_name = list(snifim_df['Name'])
snif_address = List(snifim_df['Address'])

html = """  <h4>Mcdonalds</h4>
            Snif_Adress: %s

"""

for lat,lon,name,add in zip(snif_lat,snif_lon,snif_name,snif_address):
    iframe = folium.Iframe(html = html % str(add),width=200, height=100)
    fg.add_child(folium.Marker(location=[lat,lon],popup=folium.Popup(iframe),icon="glyphicon glyphicon-piggy-bank"))


Mcmap.add_child(fg)
Mcmap.save("test.html")
Asked By: michox2

||

Answers:

Shooting in the dark here….

try:

pip3 install folium

It may be that it is installed for python 2.7 but not 3.x

Answered By: Paul Lemmons

2 possibilities come to my mind:

  • the first one, cited by Paul, is that you installed it with pip (for Python 2) and you try using it with Python 3 (so you need to install it with pip3 as cited in Paul’s answer)

  • You have a script file named folium(.py) and you should rename it

Answered By: FoxYou

python3 -m pip install <package_name>

This ensures that you’re installing the package in the python version you’re using.

Answered By: Siddharth Prajosh

I encountered a similar error while working with VSCode Jupyter Notebook. After installation, I had to restart the kernel by using the command Ctrl+Shift+P -> Restart Kernel. I then created a separate Python file in the same folder and imported Folium there to check it. After that, I was able to use it in the notebook as well.
enter image description here

Answered By: Rasul
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.