91

I installed openpyxl with

$ pip install openpyxl

when I try the command

from openpyxl import Workbook

I get

Traceback (most recent call last):
 File "<pyshell#0>", line 1, in <module>
from openpyxl import Workbook
ImportError: No module named 'openpyxl'

I am using Python 3.4 and Ubuntu 14.04, 32-bit OS type

ForceBru
  • 43,482
  • 10
  • 63
  • 98
FrancescoVe
  • 1,060
  • 1
  • 7
  • 12

11 Answers11

73

If you don't use conda, just use :

pip install openpyxl

If you use conda, I'd recommend :

conda install -c anaconda openpyxl

instead of simply conda install openpyxl

Because there are issues right now with conda updating (see GitHub Issue #8842) ; this is being fixed and it should work again after the next release (conda 4.7.6)

ToddEmon
  • 1,140
  • 1
  • 12
  • 16
52

@zetysz and @Manish already fixed the problem. I am just putting this in an answer for future reference:

  • pip refers to Python 2 as a default in Ubuntu, this means that pip install x will install the module for Python 2 and not for 3

  • pip3 refers to Python 3, it will install the module for Python 3

Caridorc
  • 6,222
  • 2
  • 31
  • 46
20

In order to keep track of dependency issues, I like to use the conda installer, which simply boils down to:

conda install openpyxl
Archie
  • 2,247
  • 1
  • 18
  • 35
11

I had the same problem solved using instead of pip install :

sudo apt-get install python-openpyxl
sudo apt-get install python3-openpyxl

The sudo command also works better for other packages.

rainer
  • 3,295
  • 5
  • 34
  • 50
11

You have to install it explixitly using the python package manager as

  1. pip install openpyxl for Python 2
  2. pip3 install openpyxl for Python 3
utkarshh12
  • 111
  • 1
  • 3
8

If you're using Python3, then install:

python3 -m pip install --user xlsxwriter

This will run pip with the appropriate version of Python3. If you run bare pip3 and have many versions of Python install, it will still fail leading to more confusion.

The --user flag will allow to install as a regular user and no require root.

reisy
  • 191
  • 2
  • 4
  • Is it more compatible with python 3 or is just your preference? I'm stuck with an openpyxl bug, works fine on windows, but not on Ubuntu server... – C. S. F. Junior May 07 '20 at 13:01
  • Like I said above, it's more precise than using pip or pip3; it works on all platforms equally well. What's the nature of your problem? What did you see when you ran the above command? What errors are you getting when you try to use this library? – Frederick Ollinger Nov 05 '20 at 04:22
4

This work for me in Windows, if you want to export or read from Excel

pip install openpyxl
pip install --user xlsxwriter
pip install xlrd==1.2.0
Gustavo Marquez
  • 419
  • 4
  • 6
3

I still was not able to import 'openpyxl' after successfully installing it via both conda and pip. I discovered that it was installed in '/usr/lib/python3/dist-packages', so this https://stackoverflow.com/a/59861933/10794682 worked for me:

import sys 
sys.path.append('/usr/lib/python3/dist-packages')

Hope this might be useful for others.

ConZZito
  • 325
  • 2
  • 5
  • 2
    None of the other solution I found worked for me in a Python 3.8 venv I used the following: ```import sys sys.path.append('./env/lib/python3.8/site-packages') ``` – smartexpert Mar 08 '21 at 21:39
2

This is what worked for me:

pip uninstall openpyxl
pip install openpyxl 

Or you can also try

pip3 uninstall openpyxl
pip3 install openpyxl 

If you are using notebooks such as google-colab, jupyter-notebook, etc you can try this:

!pip uninstall openpyxl
!pip install openpyxl 

Or using pip3

!pip3 uninstall openpyxl
!pip3 install openpyxl 

Then you may need to restart your notebook if you are using a notebook.

crispengari
  • 7,901
  • 7
  • 45
  • 53
1

Open PyCharm Package and install OPENPYXL. Its working.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 21 '22 at 16:51
0

What worked with me, including many of the above solutions, is to work in with venv, pip install all the requirements in the new virtual environment and run the program.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31513864) – Shiplu Mokaddim Apr 14 '22 at 22:40