Error: "Import Pandas" fails on Jupyter notebook in Python3 - python

I am having an issue trying to import pandas on my Jupyter notebook using Python 3.10. I am using a MacOS computer with VSCode as my IDE.
I have installed pandas on my machine using Homebrew brew install pandas and it works just fine when I use import pandas in my IDE. However, it fails in Jupyter.
I open jupyter as normal with jupyter notebook. I then attempt the simple command import pandas I get an error message that says:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import pandas
ModuleNotFoundError: No module named 'pandas'
I did a quick search on Stack and across Google and everybody tells me to run !pip install pandas in the Jupyter notebook but since I am using PHP3.10, I have opted for !pip3 install pandas. When I do this, Jupyter tells me:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pandas in /Users/daveshields/Library/Python/3.10/lib/python/site-packages (1.4.2)
Requirement already satisfied: python-dateutil>=2.8.1 in /Users/daveshields/Library/Python/3.10/lib/python/site-packages (from pandas) (2.8.2)
Requirement already satisfied: numpy>=1.21.0 in /Users/daveshields/Library/Python/3.10/lib/python/site-packages (from pandas) (1.22.4)
Requirement already satisfied: pytz>=2020.1 in /Users/daveshields/Library/Python/3.10/lib/python/site-packages (from pandas) (2022.1)
Requirement already satisfied: six>=1.5 in /Users/daveshields/Library/Python/3.10/lib/python/site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)
I close Jupyter and then open it again and attempt import pandas and I get the exact same message. Can anyone help me figure out why this is happening? I am doing the Python Master Course by Ardit Sulce on Udemy but I can't progress any further in the course until I can figure this out. TYIA.
Dave Shields

Thank you so much to Wayne!
Amazingly the %pip install pandas worked! I did that and it installed pandas and numpy.
I ran import pandas and then df1 = pandas.DataFrame([[2,4,6],[10,30,30]]).
After that I was able to successfully use print(df1) and it worked!

You can use:
import sys
!{sys.executable} -m pip install pandas
If you already have Pandas in your system and still not able to load it then :
import sys
sys.path.append('your-path')

Related

Unable to import pandas in Replit.com

import pandas
So I am working on a python project and want to import pandas library on https://replit.com/~
For some reasons, it shows some attribute error when I run the project.
Does anyone know ho do I fix or manually install pandas on replit?
Attaching Screenshot of an error herewith.
Usually packages have a lot of errors in replit but you can try this: -
Pandas does actually work on repl.it - you have to install it from the package manager. To do so, click the cube on the side navigation bar and type pandas into the search box. Then click on the pandas search entry and hit the plus sign. Tell me if this works!
Or
Broken package installs can usually be fixed by,
Updating pip and installing pandas from PyPI. By default, Repl.it comes with pip version 19.3.1, but the latest available version for python 3.8 is pip-21.1.1.
~/repl$ pip -V
pip 19.3.1 from /opt/virtualenvs/python3/lib/python3.8/site-packages/pip (python 3.8)
~/repl$ pip install pandas
Requirement already satisfied: numpy>=1.16.5 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from pandas) (1.20.2)
Collecting pytz>=2017.3
Using cached https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Installing collected packages: pytz, pandas
Successfully installed pandas-1.2.4 pytz-2021.1
Pandas does not work on replit at all, because a lot of modules, which Pandas needs to work properly, do not work in replit. An online Compiler is also not the best choice for doing dataprocessing, it would be better if you install an Interpreter for python on your PC.

Why can't python find my installed libaries?

I use python 3.9 and it is no longer able to find the libraries that I have installed libaries even though they are installed.
When I for example import pandas I get this message,
>>> import pandas
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
When I use pip to install the library it tells me that it already has been installed.
C:\Users\malth>pip install pandas
Requirement already satisfied: pandas in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (1.2.3)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (2021.1)
Requirement already satisfied: numpy>=1.16.5 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (1.20.1)
Requirement already satisfied: six>=1.5 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
I can even see the library in the site-packages folder.
Try creating virtual environment, configure it and then install whatever module you require. Its the most easiest way to skip module error anytime.
Try to do pip --version. If you have a multiple pythons on your pc, you might have a pip that linked to another version.
I guess you should try to use pyenv or virtualenv. This modules allowed you to avoid situation which I described above. Also it's a good practice to keep you python env isolated for a specific project.
As N.Singh has suggested, I would try to set up a new conda environment, adding all possible packages or libraries you will use and then I will make it active. Information about it can be found here: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment.
I really hope this helps. I have already had the same problem few months ago and worked for me.

ModuleNotFoundError: No module named 'pdfplumber'

I would like to import pdfplumber and tried
import pdfplumber
and caught error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-b3d6737fd8e1> in <module>
----> 1 import pdfplumber
ModuleNotFoundError: No module named 'pdfplumber'
Tried to install using pip3 install pdfplumber and it returned:
Requirement already satisfied: pdfplumber in c:\python38\lib\site-packages (0.5.26)
Requirement already satisfied: pdfminer.six==20200517 in c:\python38\lib\site-packages (from pdfplumber) (20200517)
Requirement already satisfied: Wand in c:\python38\lib\site-packages (from pdfplumber) (0.6.5)
Requirement already satisfied: Pillow>=7.0.0 in c:\python38\lib\site-packages (from pdfplumber) (7.2.0)
Requirement already satisfied: sortedcontainers in c:\python38\lib\site-packages (from pdfminer.six==20200517->pdfplumber) (2.3.0)
Requirement already satisfied: chardet in c:\users\harper.guo\appdata\roaming\python\python38\site-packages (from pdfminer.six==20200517->pdfplumber) (3.0.4)
Requirement already satisfied: pycryptodome in c:\python38\lib\site-packages (from pdfminer.six==20200517->pdfplumber) (3.10.1)
WARNING: You are using pip version 20.3.3; however, version 21.0.1 is available.
You should consider upgrading via the 'c:\python38\python.exe -m pip install --upgrade pip' command.
But Command Prompt showed that I already have installed the module?
>>> pdfplumber
<module 'pdfplumber' from 'C:\\Python38\\lib\\site-packages\\pdfplumber\\__init__.py'>
But import pdfplumber returned the same erro. How to import pdfplumber?
I guess it has to do with the Python version that I used.
In the top right hand corner of VS Code it shows that my Python version was Python 3
Clicking on it and changing it to Python 3.8.5 and the code worked. This was done after I restarted VS Code and my laptop, and created new path.
Creating a new path in Environment Variables following these resources:
1. 'pip' is not recognized as an internal or external command
2. 2020 How to Fix "No Module Named..." Error in Python | Python Tutorial
3. Python Virtual Environments: A Primer
4. '' is not recognized as an internal or external command, operable program or batch file

Can't import Pyomo in Jupyter Notebook

I'm trying to import pyomo in Jupyter Notebook, I ran the following code:
!pip3 install pyomo
import pyomo
THEN it came back:
Requirement already satisfied: pyomo in /Users/*/Library/Python/3.8/lib/python/site-packages (5.7.3) Requirement already satisfied: PyUtilib>=6.0.0 in /Users/*/Library/Python/3.8/lib/python/site-packages (from pyomo) (6.0.0)
Requirement already satisfied: six>=1.4 in /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages (from pyomo) (1.15.0) Requirement already satisfied: ply in /Users/*/Library/Python/3.8/lib/python/site-packages (from pyomo) (3.11)
Requirement already satisfied: nose in /Users/*/Library/Python/3.8/lib/python/site-packages (from PyUtilib>=6.0.0->pyomo) (1.3.7)
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-5-7105a3440ba3> in <module> 1 get_ipython().system('pip3 install pyomo') ----> 2 import pyomo
ModuleNotFoundError: No module named 'pyomo'
I think I already installed pyomo, but when I try to import the module, it cannot be found.
Please someone helps to resolve this issue.
import pyomo doesnt work. as written in the doc you should use this package like:
from pyomo.environ import * or like:
import pyomo.environ

import error: No module named Pandas Anaconda

I have Python2 and Python3 both installed in my laptop. I am trying to run pandas in Jupyter Notebook, but it shows an error message saying:
No module named 'pandas'
I have tried to install pandas in both python2 and python3 using:
pip3 install pandas
and
conda install pandas
both methods successfully installed the package but when I tried to import pandas, it shows the Error message again. I then tried:
!pip3 install pandas
but then it shows:
Requirement already satisfied: pandas in c:\users\fusuy\appdata\local\programs\python\python38-32\lib\site-packages (1.0.3)
Requirement already satisfied: pytz>=2017.2 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from pandas) (2019.3)
Requirement already satisfied: python-dateutil>=2.6.1 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: numpy>=1.13.3 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from pandas) (1.18.1)
Requirement already satisfied: six>=1.5 in c:\users\appdata\local\programs\python\python38-32\lib\site-packages (from python-dateutil>=2.6.1->pandas) (1.14.0)
What should I do now?
Python is case sensitive. No module named 'Pandas' doesn't mean there is no module 'pandas'. Try: import pandas as pd. Besides that I wonder that conda install pandas was working, since your Python paths don't look like an Anaconda installation. However, if you're using conda, you first need to conda activate an environment before you can use it.
I had the same problem here.
I realize that I was trying to run the script without write python before the name script.
Beginners mistake... at least on my case

Categories