0

I am trying to import pandasql. I am running the following code in a jupyter notebook running python:

!pip install pandasql
from pandasql import sqldf
import pandas as pd

This logs an error saying ModuleNotFoundError: No Module name 'pandasql'

I understand this is a common problem and have tried using the following SO posts to fix the solution without results:

ImportError: No module named pandas

How to fix ModuleNotFoundError: No module named 'pandas_datareader'

pandasql will not import : ImportError: cannot import name to_sql

charles
  • 99
  • 1
  • 2
  • 11

4 Answers4

3

I know I am quite late in responding this but try this, but as you are working on Jupyter notebook, you can try pip install pandasql in Anaconda prompt

kimcodes
  • 736
  • 1
  • 6
  • 16
Mam1004
  • 71
  • 8
  • Note that if users have installed Anaconda/conda in their system, then they have made the choice that Anaconda/conda is their primary package manager from that time forward. It is highly advisable for makine robust, stable, and portable environments to actually always primarily use Anacaona/conda to install packages then. So for this case, since the Anaconda prompt is stated here, it should be `conda install -c conda-forge pandasql` or in the notebook `%conda install -c conda-forge pandasql`, based on [here](https://anaconda.org/conda-forge/pandasql). (See about the magic install commands ... – Wayne Jul 14 '23 at 12:20
  • that you can run in the notebook to insure the installation occurs in the environment where the kernel underlying the active notebook is running[here](https://stackoverflow.com/questions/28828917/error-importing-seaborn-module-in-python-importerror-cannot-import-name-utils/76347896#comment134631387_41925357).) **If Anaconda/conda is on your system, only fall back to using `pip install` for packages that you absolutely cannot find an Anaconda/conda recipe for installing.** – Wayne Jul 14 '23 at 12:22
1

I think either your python you are using is wrong/doesn't have the code, or you haven't installed or printed it right.

1010011010
  • 45
  • 1
  • 1
  • 12
0

I encountered the same issue and solved it. I first checked if pandasql was installed or not. I searched for pandasql in the file explorer and founded it somewhere, I copied the pandasql file and placed it in anaconda3\Lib\site-packages. Then, the issue was solved

0

it is due to !pip install as this install the library at base environment in jupyter notebook.

But pip install installs the library in local/current environment.

  • For more context... Explicitly, running `%pip install ` with the magic symbol at the start in a cell inside the `.ipynb` file insures the package installs in the environment that the kernel underlying the active notebook is running. Leaving off that symbol causes Jupyter to usually fall back to trying the magic command anyway because generally automagics is on by default in Jupyter so that any word that isn't a Python keyword at the state, Jupyter will behind-the-scenes add the magic symbol and try to run the equivalent. So that is why it works without any symbol. With the ... – Wayne Jul 14 '23 at 12:10
  • Adding the exclamation point in front triggers Jupyter to run the command off in a temporary shell instance. If that temporary shell instance isn't the same environment in which Jupyter is running, than it doesn't really help because the installation happens in the environment that Jupyter doesn't see. See the second paragraph [here](https://discourse.jupyter.org/t/location-of-libraries-or-extensions-installed-in-jupyterlab/16303/2?u=fomightez) on why that may be the case on a system as more reason to not use an exclamation point with the install commands. FInally, to see more ... – Wayne Jul 14 '23 at 12:14
  • about the magic install commands (both `%pip install` and `%conda install`) that were added to help insure installation occurs in the correct environment backing the notebook [here](https://stackoverflow.com/questions/28828917/error-importing-seaborn-module-in-python-importerror-cannot-import-name-utils/76347896#comment134631387_41925357). – Wayne Jul 14 '23 at 12:16