I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.
I've been faced to Module Not Found Error in a script which all it's requirements has been installed. I'm trying to import spatial library:
import spatial
This library is located here:
C:\Users\ASUS\AppData\Local\Programs\Python\Python37\Lib\site-packages\scipy\spatial
I checked installed packages through pip list and it was okay. I tried to install spatial-lib in Pycharm project environment but it couldn't be done:
Could not find a version that satisfies the requirement spatial-lib (from versions: )
No matching distribution found for spatial-lib
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
It's nonesence, because my pip is up-to-date. Maybe good to say, importing scipy has such probelms too.
It looks like spatial is a sub-package of scipy. Therefore, to import spatial, you should use the following:
from scipy import spatial
Tried cloning git to Jupyter folder on Windows. No progress.
I have installed SKMultilearn in the same folder as Jupyter.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-22-b987f02e7825> in <module>()
5 return_indicator = 'sparse', allow_unlabeled = False)
6
----> 7 from skmultilearn.adapt import MLkNN
8
9 classifier = MLkNN(k=20)
ModuleNotFoundError: No module named 'skmultilearn'
I faced the same issue and couldn't find a solution. Remember, you must have installed skmultilearn first from cmd, pip install scikit-multilearn. If you have done this and still Jupyter Notebook is saying ModuleNotFoundError: No module named 'skmultilearn', then my solution is for you.
I tried and managed to find an easy solution. I hope that you might have found a solution as this question was asked 3 years ago. I am posting this because many new users will be facing this issue.
Open Jupyter Notebook terminal and go into python.
Type, help('modules'). You will get a list of all packages available to you. 99% chance is that you will not find skmultilearn in that list.
Now, go to command prompt aka cmd.
Type, pip3 install ipykernel --upgrade, then py -3 -m ipykernel install --user, you will get this, Installed kernelspec python3 in C:\Users\MC\AppData\Roaming\jupyter\kernels\python3.
Now type, pip install scikit-multilearn. It will say Requirement already satisfied: scikit-multilearn in c:\python396\lib\site-packages (0.2.0)
Good now type, pip3 install jupyter.
Then, again install pandas and seaborn as your need, pip install pandas and pip install seaborn.
Enjoy, issue resolved. You will not face this error :)
Are you sure that skmultilearn has been correctly installed? It does not depend on the subdirectory where you did the installation.
Open a terminal window in your Jupyter browser, go into python
ipython
and then check out the modules that has been installed:
[1] help('modules')
You will get a list of all packages available to you. skmultilearn should be in the list if it was correctly installed.
pip install scikit-multilearn
pip install scikit-multilearn
I am trying to read a .xlsx with pandas, but get the follwing error:
data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
Traceback (most recent call last):
File "/Users/Vineeth/PycharmProjects/DataAnalysis1/try1.py", line 9, in <module>
data = pd.read_excel(low_memory=False, io="DataAnalysis1/temp1.xlsx").fillna(value=0)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/util/_decorators.py", line 118, in wrapper
return func(*args, **kwargs)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 230, in read_excel
io = ExcelFile(io, engine=engine)
File "/Users/Vineeth/venv/lib/python2.7/site-packages/pandas/io/excel.py", line 263, in __init__
raise ImportError(err_msg)
ImportError: Install xlrd >= 0.9.0 for Excel support
I've also tried
data = pd.read_excel("DataAnalysis1/temp1.xlsx", low_memory=False).fillna(value=0)
And I Still get the same error.
Background: I'm trying to extract an excel file with multiple worksheets as a dict of data frames.I installed xlrd version 0.9.0 and the latest version(1.1.0) but I still get the same error. Thanks!
As #COLDSPEED so eloquently pointed out the error explicitly tells you to install xlrd.
pip install xlrd
And you will be good to go.
Since December 2020 xlrd no longer supports xlsx-Files as explained in the official changelog. You can use openpyxl instead:
pip install openpyxl
And in your python-file:
import pandas as pd
pd.read_excel('path/to/file.xlsx', engine='openpyxl')
Either use:
pip install xlrd
And if you are using conda, use
conda install -c anaconda xlrd
That's it. good luck.
If you are in ubuntu this work for me:
python3 -m pip install openpyxl
python3 -m pip install xlrd
This happened to me after I ran a script with cProfile a la python3 -m cProfile script.py even though xlrd was already installed and had never thrown this error before. it persisted even under python3 script.py. (Granted, I agree this wasn't what happened to OP, given the obvious import error)
However, for cases like mine, the following fixed the issue, despite being told "requirement already met" in every case.
pip install --upgrade pandas
pip install --upgrade xlrd
Pretty confounding stuff; not sure if cProfile was the cause or just a coincidence
The following should work, assuming your pip install operated on python2.
python3 -m pip install xlrd
I was getting an error
"ImportError: Install xlrd >= 1.0.0 for Excel support"
on Pycharm for below code
import pandas as pd
df2 = pd.read_excel("data.xlsx")
print(df2.head(3))
print(df2.tail(3))
Solution : pip install xlrd
It resolved error after using this.
Also no need to use "import xlrd"
This works for me:
For Python 3
pip3 install xlrd --user
For Python2
pip install xlrd --user
I don't know if this will be helpful for someone, but I had the same problem.
I wrote pip install xlrd in the anaconda prompt while in the specific environment and it said it was installed, but when I looked at the installed packages it wasn't there.
What solved the problem was "moving" (I don't know the terminology for it) into the Scripts folder of the specific environment and do the pip install xlrd there.
Hope this is useful for someone :D
Was getting the error while I was using jupyter.
ModuleNotFoundError: No module named 'xlrd'
...
ImportError: Install xlrd >= 0.9.0 for Excel support
it was resolved for me after using.
!pip install xlrd
I encountered same problem and took 2 hours to figure it out.
pip install xlrd (latest)
pip install pandas (latest)
Go to C:\Python27\Lib\site-packages and check for xlrd folder (if there are 2 of them) delete the old version
open a new terminal and use pandas to read excel. It should work.
I had the same problem and none of the above answers worked. If you go into the settings (CTRL + ALT + s) and search for project interpreter you will see all of the installed packages. Click the + button at the top right and search for xlrd, then click install package at the bottom left.
I had already done the "pip install xlrd" command from the file location of my python.exe before this, so you may need to do that as well. (you can find the file location by searching it in windows search bar and right click -> open file location, then type cmd into the file explorer address bar)
This can be because your required libraries are been installed in Python environment instead of Spyder.
https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder
I had the same problem. Actually, the problem is that even after installing packages/libraries using pip these packages are not integrated with IDE. So, need to add libraries specifically to the ide.
First of all you need to install xlrd & pandas packages. Then try below code.
import xlrd
import pandas as pd
xl = pd.ExcelFile("fileName.xlsx")
print(xl.parse(xl.sheet_names[0]))
You need to install the "xlrd" lib
For Linux (Ubuntu and Derivates):
Installing via pip:
python -m pip install --user xlrd
Install system-wide via a Linux package manager:
*sudo apt-get install python-xlrd
Windows:
Installing via pip:
*pip install xlrd
Download the files:
https://pypi.org/project/xlrd/
Another possibility, is the machine has an older version of xlrd installed separately, and it's not in the "..:\Python27\Scripts.." folder.
In another word, there are 2 different versions of xlrd in the machine.
when you check the version below, it reads the one not in the "..:\Python27\Scripts.." folder, no matter how updated you done with pip.
print xlrd.__version__
Delete the whole redundant sub-folder, and it works. (in addition to xlrd, I had another library encountered the same)
I encountered a similar issue trying to use xlrd in jupyter notebook. I notice you are using a virtual environment and that was the key to my issue as well. I had xlrd installed in my venv, but I had not properly installed a kernel for that virtual environment in my notebook.
To get it to work, I created my virtual environment and activated it.
Then... pip install ipykernel
And then... ipython kernel install --user --name=myproject
Finally, start jupyter notebooks and when you create a new notebook, select the name you created (in this example, 'myproject')
Hope that helps.
Please make sure your python or python3 can see xlrd installation. I had a situation where python3.5 and python3.7 were installed in two different locations. While xlrd was installed with python3.5, I was using python3 (from python3.7 dir) to run my script and got the same error reported above. When I used the correct python (viz. python3.5 dir) to run my script, I was able to read the excel spread sheet without a problem.
As #WojciechJakubas mentioned to install openpyxl instead of xlrd, I used openpyxl and it worked.
pip install openpyxl
import openpyxl
path = "path to file.xlxs"
wb_obj = openpyxl.load_workbook(path)
sheet_obj = wb_obj.active
length_col = sheet_obj.max_row
print("Length of rows : ", length_col)
I hope it will help lot of people in 2023.
I am working on a Macbook with Python 2.7.5 pre-installed. I installed the pandas package via command-line with the following code.
pip install pandas
This completed without errors. However, when I try to run the following code in Netbeans, I get an error.
if __name__ == "__main__":
import pandas as pd
The error is: ImportError: No module named pandas
When I try to re-install the pandas package in the terminal I get the message: Requirement already satisfied (use --upgrade to upgrade): pandas in /usr/local/lib/python2.7/site-packages
What am I doing wrong here?
Thanks for the help!