Why users can install modules from pip but not from conda?

Why could I import googlemaps module in line 7 after pip install googlemaps but not after conda install googlemaps?

I understand a server reset will remove any new modules, but I would still like my users to have the capability of installing short-lived modules using either pip or conda.

If you give us more information about your user environment, for example your Dockerfile, any customisations you’ve made to your JupyterHub setup (ideally show us your Z2JH config with secrets redacted), and the full notebook, we might be able to help.

1 Like

I’m using vanilla jupyter/datascience-notebook, no customizations at all. Would you please point me the relevant part in the configuration you think may be related to this issue?

Notebook source:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6c2659d0-31f4-45df-9d35-205146519722",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting package metadata (current_repodata.json): | \n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "conda install googlemaps -c conda-forge --yes --force-reinstall"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f37652c7-7e1c-4f6b-8834-9e8e6cdffafb",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'googlemaps'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_167/3164823033.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mgooglemaps\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'googlemaps'"
     ]
    }
   ],
   "source": [
    "import googlemaps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "08d49339-527c-4ee8-90c1-6b58fcfe7df2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting googlemaps\n",
      "  Using cached googlemaps-4.5.3-py3-none-any.whl\n",
      "Requirement already satisfied: requests<3.0,>=2.20.0 in /opt/conda/lib/python3.9/site-packages (from googlemaps) (2.26.0)\n",
      "Requirement already satisfied: charset-normalizer~=2.0.0 in /opt/conda/lib/python3.9/site-packages (from requests<3.0,>=2.20.0->googlemaps) (2.0.0)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.9/site-packages (from requests<3.0,>=2.20.0->googlemaps) (1.26.6)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.9/site-packages (from requests<3.0,>=2.20.0->googlemaps) (3.1)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.9/site-packages (from requests<3.0,>=2.20.0->googlemaps) (2021.5.30)\n",
      "Installing collected packages: googlemaps\n",
      "Successfully installed googlemaps-4.5.3\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install googlemaps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1a7f637f-d3e1-4a13-938e-4c1a91fa0db0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import googlemaps"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

On the off-chance you’ve missed it, in the first half of 2019 the %pip and %conda magics were added and are now the current best way to be running installs in the notebook.
The following are the current ways to use conda and pip in a notebook:

%pip install <python_package_name>
%conda install <dependency_name>

See here for more details.

More examples promoting this:

2 Likes
ModuleNotFoundError: No module named 'mglearn'
ModuleNotFoundError: No module named 'ase'
How to run a notebook using command line
Cannot get to command prompt mode in Jupyter Notebook
Module Not Found
JupyterHub (LTJH) on Raspberry Pi 5
Cv2 package doesn't work
I want to import Keras, but I've tried many ways to do it wrong.
Need help with Jupyter Notebook
Jupyter lab notebook `No Module Named` error upon importing installed packages
Wget not recognised as an internal or external command
How to install cesiumpy
No module named 'matplotlib'
How do I use scikit-survival in the online Jupyter Notebook?
Where is teminal mode?
Jupyter Kernel not running same Python version as the Virtual Environment
How to install package and display pandas dataframe inside the tab?
How to import Seaborn in Jupiter Notebook
`command not found` message in Notebook for installed package
Binder & Tesseract?
No module named 'ipympl' found
Trouble with pip installation
Jupytext with JupyterLab Desktop in conda environment
!pip install occur permission problem in notebook
Different package versions in terminal and jupyter notebook
Jupyter Notebook wrong directory. Unable to import seaborn
Cloning git to Binder Jupyter Lab
Help needed! Constantly getting ValueError: Format specifier missing precision
Jupyter-ai generate function produces error
Am I doing wrong ! Is this not very basic?
Unable to resolve "No module named 'seaborn' error in Jupyter Notebook
Getting administrator access so I can access jupyter notebook

Thank you. I wasn’t aware of that. Unfortunately I’m still unable to import the module after %conda install googlemaps -c conda-forge --yes (%pip install googlemaps works just fine).

In the output cell for the conda installation, it suggests restarting the kernel, have you tried that?