No module named xlrd python

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named xlrd #50

ImportError: No module named xlrd #50

Comments

A coworker complained about this, so I tried it myself. When I try to pip-install cutplace in a fresh virtual environment, I get «ImportError: No module named xlrd». I see xlrd specified as a requirement in cutplace’s setup.py, however, so I don’t understand what’s going on. Apologies if this is some sort of configuration error on my side. Disclaimer: I’m not a Python guru.

Versions: Python 2.7.2, setuptools 0.6c11, pip 1.3.1 (from running python in the activated environment, importing setuptools and pip and printing them). Mac OS X 10.7, BTW.

pip install -r requirements.txt Downloading/unpacking cutplace (from -r requirements.txt (line 1)) Downloading cutplace-0.7.1.zip (580kB): 580kB downloaded Running setup.py egg_info for package cutplace Traceback (most recent call last): File "", line 16, in File "/Users/Me/Documents/code/python/test-env/build/cutplace/setup.py", line 33, in from cutplace import _cutplace File "cutplace/_cutplace.py", line 26, in import xlrd ImportError: No module named xlrd Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 16, in File "/Users/Me/Documents/code/python/test-env/build/cutplace/setup.py", line 33, in from cutplace import _cutplace File "cutplace/_cutplace.py", line 26, in import xlrd ImportError: No module named xlrd 

The text was updated successfully, but these errors were encountered:

Читайте также:  Удалить ведущие нули python

Источник

No module named xlrd python

Last updated: Feb 22, 2023
Reading time · 10 min

banner

# ModuleNotFoundError: No module named ‘xlrd’ in Python

The Python «ModuleNotFoundError: No module named ‘xlrd'» occurs when we forget to install the xlrd module before importing it or install it in an incorrect environment.

To solve the error, install the module by running the pip install xlrd command.

no module named xlrd

Open your terminal in your project’s root directory and install the xlrd module.

Copied!
# 👇️ in a virtual environment or using Python 2 pip install xlrd # 👇️ for python 3 (could also be pip3.10 depending on your version) pip3 install xlrd # 👇️ if you get permissions error sudo pip3 install xlrd pip install xlrd --user # 👇️ if you don't have pip in your PATH environment variable python -m pip install xlrd # 👇️ for python 3 (could also be pip3.10 depending on your version) python3 -m pip install xlrd # 👇️ using py alias (Windows) py -m pip install xlrd # 👇️ for Anaconda conda install -c conda-forge xlrd # 👇️ for Jupyter Notebook !pip install xlrd

After you install the xlrd package, try importing it as follows.

Copied!
import xlrd book = xlrd.open_workbook("example.xls") print("The number of worksheets is ".format(book.nsheets)) print("Worksheet name(s): ".format(book.sheet_names()))

# Common causes of the error

The error occurs for multiple reasons:

  1. Not having the xlrd package installed by running pip install xlrd .
  2. Installing the package in a different Python version than the one you’re using.
  3. Installing the package globally and not in your virtual environment.
  4. Your IDE running an incorrect version of Python.
  5. Naming your module xlrd.py which would shadow the official module.
  6. Declaring a variable named xlrd which would shadow the imported variable.
Читайте также:  Css flip background image

If the error persists, get your Python version and make sure you are installing the package using the correct Python version.

get python version

For example, my Python version is 3.10.4 , so I would install the xlrd package with pip3.10 install xlrd .

Copied!
pip3.10 install xlrd # 👇️ if you get permissions error use pip3 (NOT pip3.X) sudo pip3 install xlrd

Notice that the version number corresponds to the version of pip I’m using.

If the PATH for pip is not set up on your machine, replace pip with python3 -m pip :

Copied!
# 👇️ make sure to use your version of Python, e.g. 3.10 python3 -m pip install xlrd

If the error persists, try restarting your IDE and development server/script.

# Check if the package is installed

You can check if you have the xlrd package installed by running the pip show xlrd command.

Copied!
# 👇️ check if you have xlrd installed pip show xlrd # 👇️ if you don't have pip set up in PATH python -m pip show xlrd

The pip show xlrd command will either state that the package is not installed or show a bunch of information about the package, including the location where the package is installed.

# Make sure your IDE is using the correct Python version

If the package is not installed, make sure your IDE is using the correct version of Python.

If you have multiple Python versions installed on your machine, you might have installed the xlrd package using the incorrect version or your IDE might be set up to use a different version.

For example, In VSCode, you can press CTRL + Shift + P or ( ⌘ + Shift + P on Mac) to open the command palette.

Then type «Python select interpreter» in the field.

python select interpreter

Then select the correct python version from the dropdown menu.

Читайте также:  Php 4 release date

select correct python version

Your IDE should be using the same version of Python (including the virtual environment) that you are using to install packages from your terminal.

# Install the package in a Virtual Environment

If you are using a virtual environment, make sure you are installing xlrd in your virtual environment and not globally.

You can try creating a virtual environment if you don’t already have one.

Copied!
# 👇️ use correct version of Python when creating VENV python -m venv venv # 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ install xlrd in virtual environment pip install xlrd

If the python -m venv venv command doesn’t work, try the following 2 commands:

Your virtual environment will use the version of Python that was used to create it.

If the error persists, make sure you haven’t named a module in your project as xlrd.py because that would shadow the original xlrd module.

You also shouldn’t be declaring a variable named xlrd as that would also shadow the original module.

# Try reinstalling the package

If the error is not resolved, try to uninstall the xlrd package and then reinstall it.

Copied!
# 👇️ check if you have xlrd installed pip show xlrd # 👇️ if you don't have pip set up in PATH python -m pip show xlrd # 👇️ uninstall xlrd pip uninstall xlrd # 👇️ if you don't have pip set up in PATH python -m pip uninstall xlrd # 👇️ install xlrd pip install xlrd # 👇️ if you don't have pip set up in PATH python -m pip install xlrd

Try restarting your IDE and development server/script.

You can also try to upgrade the version of the xlrd package.

Copied!
pip install xlrd --upgrade # 👇️ if you don't have pip set up in PATH python -m pip install xlrd --upgrade

Источник

Оцените статью