Jupyter Notebook cannot package folium

Question:

I tried to install a package folium into Jupyter Notebook. I had to try many methods, such as add system path, upgrade pip, install setuptools but I cannot make it. My laptop is Macbook Pro, system: Catalina 10.15.3, Jupyter Notebook from Anaconda. Python version: 3.7.4

System.exectutable:

'/opt/anaconda3/bin/python'

System path:

['/Users/scott/Documents/Untitled Folder',
 '/opt/anaconda3/lib/python37.zip',
 '/opt/anaconda3/lib/python3.7',
 '/opt/anaconda3/lib/python3.7/lib-dynload',
 '',
 '/opt/anaconda3/lib/python3.7/site-packages',
 '/opt/anaconda3/lib/python3.7/site-packages/aeosa',
 '/opt/anaconda3/lib/python3.7/site-packages/IPython/extensions',
 '/Users/scott/.ipython']

The code I wrote is:

import numpy as np
import pandas as pd
import collections
import re
import matplotlib.pyplot as plt
import matplotlib
from collections import OrderedDict
from math import ceil
#!python3 -m pip install folium --user
#!python3 -m pip install branca --user
#!python3 -m pip install jinja2 --user
#!python3 -m pip install requests --user
#!pip install --user scipy
#!python -m pip install --upgrade pip
import scipy
#import branca
! pip install --user folium
import tqdm
import folium

However, I got such error:

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting folium
  Using cached folium-0.8.3-py2.py3-none-any.whl (87 kB)
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from folium) (1.12.0)
Collecting jinja2
  Using cached Jinja2-2.11.1-py2.py3-none-any.whl (126 kB)
Requirement already satisfied: numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from folium) (1.8.0rc1)
Collecting requests
  Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB)
Collecting branca>=0.3.0
  Using cached branca-0.4.0.tar.gz (41 kB)
    ERROR: Command errored out with exit status 1:
     command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zm/pks1_crj5d7d7wp4x_4sr5rm0000gn/T/pip-install-r8yciP/branca/setup.py'"'"'; __file__='"'"'/private/var/folders/zm/pks1_crj5d7d7wp4x_4sr5rm0000gn/T/pip-install-r8yciP/branca/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/zm/pks1_crj5d7d7wp4x_4sr5rm0000gn/T/pip-install-r8yciP/branca/pip-egg-info
         cwd: /private/var/folders/zm/pks1_crj5d7d7wp4x_4sr5rm0000gn/T/pip-install-r8yciP/branca/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/zm/pks1_crj5d7d7wp4x_4sr5rm0000gn/T/pip-install-r8yciP/branca/setup.py", line 41
        print(error, file=sys.stderr)  # noqa
                         ^
    SyntaxError: invalid syntax
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-201-2c07c456259d> in <module>
     17 get_ipython().system(' pip install --user folium')
     18 import tqdm
---> 19 import folium

ModuleNotFoundError: No module named 'folium'

I had confused with this error for days, could anyone help me? Thanks in advance!

Asked By: Junxu ZHANG

||

Answers:

Looks like you’re trying to work in an anaconda 3.7 environment, but your error message is complaining about being python 2.7 and it’s complaining it cannot find folium.

Did you somehow pip install the folium module while working outside your anaconda 3.7 environment?

Maybe you could try the conda navigator tool and grab the folium package that way…

Answered By: user3556757