Cells not importing modules anymore

Hello - I’m new to python/Jupyter notebook, just using this to get better at my job. My notebook was running fine until about a week ago when I started receiving errors for code cells that were running fine before. The errors I am getting is when trying to import modules, specifically geopy and requests. I haven’t changed anything and using python 3.6. Below are the errors I am receiving. Any help is greatly appreciated as I haven’t been able to figure this out at all…

ModuleNotFoundError Traceback (most recent call last)
in
9
10 get_ipython().system(“conda install -c conda-forge geopy --yes # uncomment this line if you haven’t completed the Foursquare API lab”)
—> 11 from geopy.geocoders import Nominatim # convert an address into latitude and longitude values
12
13 import requests # library to handle requests

/opt/conda/envs/Python36/lib/python3.6/site-packages/geopy/init.py in
10 “”"
11
—> 12 from geopy.geocoders import * # noqa
13 from geopy.location import Location # noqa
14 from geopy.point import Point # noqa

/opt/conda/envs/Python36/lib/python3.6/site-packages/geopy/geocoders/init.py in
131 from geopy.geocoders.googlev3 import GoogleV3
132 from geopy.geocoders.here import Here
–> 133 from geopy.geocoders.ignfrance import IGNFrance
134 from geopy.geocoders.mapbox import MapBox
135 from geopy.geocoders.opencage import OpenCage

/opt/conda/envs/Python36/lib/python3.6/site-packages/geopy/geocoders/ignfrance.py in
1 import warnings
----> 2 import xml.etree.ElementTree as ET
3
4 from geopy.compat import (
5 HTTPBasicAuthHandler,

ModuleNotFoundError: No module named ‘xml.etree’

Also this error…

ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import requests
2 from bs4 import BeautifulSoup

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/init.py in
110 from .version import copyright, cake
111
–> 112 from . import utils
113 from . import packages
114 from .models import Request, Response, PreparedRequest

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/utils.py in
22
23 from .version import version
—> 24 from . import certs
25 # to_native_string is unused here, but imported here for backwards compatibility
26 from ._internal_utils import to_native_string

/opt/conda/envs/Python36/lib/python3.6/site-packages/requests/certs.py in
13 packaged CA bundle.
14 “”"
—> 15 from certifi import where
16
17 if name == ‘main’:

ModuleNotFoundError: No module named ‘certifi’

Hi aberkowitz92,

I assume you tried restarting the kernel and do run all?

Do you care about fixing where you are running this or care more about just getting it to run?

If it is the latter…I just went to here and launched a session using the launch binder badge and was able to run both from geopy.geocoders import Nominatim and import requests with no errors after running the commands below in a cell:

%pip install geopy
%pip install requests

You’ll see from here that the launched sessions happens to be currently pinned to Python 3.6 which is what you are using, too.

So if what you are using doesn’t have any large data requirements or security issues, you can upload your notebook and run it like that probably.
At the very least it can help you diagnose if there is a general issue with the modules or import statements.

Hi fomightez,

Thanks for the response. I am really just worried about getting it running. Launching a new session using the launch binder and running the code worked, so thank you for your help!

1 Like

conda install -c conda-forge geopy --yes

Here’s a likely candidate for your problem. conda started to behave differently about a week and a half ago. I assume that’s because Anaconda is rolling out updates to their channels. Users of notebooks in IBM Watson Studio reported that their conda customizations break the kernel, though they worked fine a few days before. We observed that conda suddenly upgraded the Python version to the latest 3.7, instead of staying on the Python 3.6/3.5/2.7 version that we install. We didn’t change anything on our side, the conda version was still the same, so changes in the content of the conda channels are the only explanation I can offer.

Run conda installation commands with the option --dry-run and check what conda would do. If you find anything suspicious, for example Python minor version upgrades that you don’t want, then add additional constraints to the conda command. For example, to make sure that you stay on Python 3.6 (if that’s what you’re using), add “python=3.6” after “geopy”.

1 Like

Thanks rolweber ! This is exactly what happened to me and the timeline seems to match up when I was using the notebook in IBM Watson Studio. I did notice when I took out “conda install -c conda-forge geopy --yes”, it would be something else that would get the error. I will try out your suggestions. Thanks again!

2 Likes

I was able to install using following in notebook in IBM Watson Studio.
!conda install -c conda-forge geopy -y
I know that it was quite a few weeks old, just to share if there is anyone like me looking for solution.