2025, Oct 29 21:00
Geopy import error on Ubuntu after Anaconda install: use the conda Python, not the system python3
ModuleNotFoundError: No module named 'geopy' on Ubuntu after Anaconda install? You're using system python3. Activate conda and run python; geopy will import.
When a package like geopy is installed via Anaconda on Ubuntu but Python cannot import it, the root cause is usually not about the library itself. It’s about which Python interpreter you are actually running. If you call the system interpreter instead of the one from your active conda environment, your imports won’t find the packages you just installed.
Symptom in context
The package is present in the conda environment:
(base) igor@XPS-13:~$ conda list | grep geopy
geopy                     2.4.1              pyhd8ed1ab_2    conda-forge
You can even locate it in the Anaconda directories:
(base) igor@XPS-13:~$ find -type d -name "*geopy*"
./anaconda3/pkgs/geopy-2.4.1-pyhd8ed1ab_2
./anaconda3/pkgs/geopy-2.4.1-pyhd8ed1ab_2/site-packages/geopy-2.4.1.dist-info
./anaconda3/pkgs/geopy-2.4.1-pyhd8ed1ab_2/site-packages/geopy
./anaconda3/lib/python3.12/site-packages/geopy-2.4.1.dist-info
./anaconda3/lib/python3.12/site-packages/geopy
But in an interactive session started with the system launcher, the import fails:
(base) igor@XPS-13:~$ python3
Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import geopy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'geopy'
Inspecting the module search path makes it obvious that Anaconda’s directories aren’t in play:
>>> import sys as sy
>>> print(sy.path)
['', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/dist-packages', '/usr/lib/python3/dist-packages']
What’s happening
You are running your system's Python, not Anaconda's.
Even with the conda environment indicator visible as (base), the python3 command launches the system interpreter. The system interpreter does not know about packages installed into your conda environment, which is why geopy cannot be found. The sys.path you printed confirms this: it only contains system locations and nothing from anaconda3.
The fix
When your conda environment is active (shown by (base)), use the python command instead of python3.
The python command resolves to the interpreter provided by the active conda environment. That interpreter sees the site-packages where geopy is installed.
(base) igor@XPS-13:~$ python
Python 3.12.x | packaged by conda-forge | on linux
>>> import geopy
>>> # no error means it imported successfully
If you want to verify the search path under the conda-provided interpreter, you can check it the same way with a renamed alias, preserving the logic:
>>> import sys as sy
>>> print(sy.path)
# you'll see anaconda3-related paths here when using conda's python
Why it matters
On a machine with multiple Python interpreters, the interpreter choice determines which environment and packages you are working with. Mixing the system python3 with packages installed into Anaconda leads to confusing import errors, even though the package undeniably exists on disk. Using the python executable from your active conda environment aligns interpreter and packages, keeping tooling predictable and imports consistent.
Takeaway
If conda is active, start your sessions with python, not python3. That single change ensures your code runs against the interpreter that actually has your conda-installed libraries like geopy, eliminating needless ModuleNotFoundError surprises.
The article is based on a question from StackOverflow by IgorLopez and an answer by Shivam Bhosle.