3

I am running Windows 7 and using Python 2.7.

I have installed openpyxl using easy_install. It looks like the installation was successful. I changed the directory and fired up Python.

>>> import openpyxl
>>>

So, this should mean that Python is able to find openpyxl. However, when I execute a simple test program excell_tutorial1.py and run it, I get the following:

Traceback (most recent call last):
File "C:/Python27/playground/excell_tutorial1.py", line 7, in <module>
from openpyxl import Workbook
ImportError: No module named openpyxl

Very confusing! It could find it in prompt line but not in the program!

import os, sys

the_module ="C:\\Python27\\Lib\\site-packages\\openpyxl-2.3.3-py2.7.egg\\openpyxl"


if the_module not in sys.path:
    sys.path.append(the_module)

if the_module in sys.path:
    print sys.path.index(the_module)
    print sys.path[18]

so, this gives me:

18
C:\Python27\Lib\site-packages\openpyxl-2.3.3-py2.7.egg\openpyxl

Anyone can think of what the problem might be?

Much appreciated

EarlyCoder
  • 1,213
  • 2
  • 18
  • 42
  • Did you start it with `python excell_tutorial1.py` or just `excell_tutorial1.py` from the command line i.e. via the association of the executable to the file extensions? – Mike Müller Jan 22 '16 at 17:26
  • The problem is no more! And, I did not do anything. When I posted the question, for some reason PYTHONPATH was empty while sys.path was not and I could not write to PYTHONPATH. Then, all of a sudden this morning, everything worked. PYTHONPATH is no longer empty and the little post-install test program works. Thanks for taking the time to reply @MikeMüller – EarlyCoder Jan 23 '16 at 14:13
  • Maybe somehow you deleted all entries in PYTHONPATH by accident. Today, you opened a new shell (cmd window) and the PYTHONPATH was taken from your settings. – Mike Müller Jan 23 '16 at 16:38

8 Answers8

5

I had the same problem solved using instead of pip or easy install one of the following commands :

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
3

While not quite what you ran into here (since you state that you are using python 2.7), for those who run into this issue and are using python 3, you may be unintentionally installing to python 2 instead. To force the install to python 3 (instead of 2) use pip3 instead.

See this thread for more info: No module named 'openpyxl' - Python 3.4 - Ubuntu

Community
  • 1
  • 1
brandonbradley
  • 607
  • 5
  • 7
1

Try deleting all openpyxl material from C:\Python27\Lib\site-packages\

Once you do that try reinstalling it using pip. (This what worked for me)

1

At times this can be a simple permission issue. As it was in my case. I installed it in my local directory with my login.

python ./setup.py install 

but some of the other user were not able to import the module. They were getting this error:

ImportError: No module named openpyxl

Hence I simply gave exe permission to 'others'

chmod -R 755 

That solves the problem at least in my case.

Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
marks
  • 45
  • 4
1

Go to the directory where pip is installed, for eg.C:\Python27\Scripts and open cmd (simply type cmd in address bar ). Now run the command "pip install openpyxl". It will install the package itself. Hope this will solve your problem.

Rohit Gawas
  • 267
  • 3
  • 8
1

Try this:

!pip install openpyxl
RobC
  • 22,977
  • 20
  • 73
  • 80
0

I had the same issue on 3.8.2

I found out that python was installed in two locations on my machine (probably py and python, just a guess) Here:

C:\Users<userAccount>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38

and Here:

C:\Python38

I deleted the one in my C drive and everything is working well now. I would double check to see where your packages are getting installed first, before deleting. Which ever one is being used, keep that one.

For this case, check to see where this package got installed:

C:\Users\<userAccount>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38\site-packages\openpyxl

keep that directory.

patti_jane
  • 3,293
  • 5
  • 21
  • 26
0

What worked for me was to open the terminal as an administrator, cd to the 'scripts' file of where python (different for each version) is stored, and then install using pip:

cd C:\Users\Salfa\AppData\Local\Programs\Python\Python39\Scripts

pip install openpyxl

This resolved the problem for me.

Saalar
  • 1