2

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

3
  • 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? Commented Jan 22, 2016 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 Commented Jan 23, 2016 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. Commented Jan 23, 2016 at 16:38

10 Answers 10

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Crazy that PIP isn't convenient for installation of Python modules...
Uhh what if sudo doesn't wanna work? It's "not a recognized command"
@Dan I guess the answerer didn't pay attention much, actually the poster asked for Windows and 'sudo' is not a Windows command, it's a Linux's one.
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

Comments

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)

Comments

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.

Comments

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.

Comments

1

Try this:

!pip install openpyxl 

1 Comment

please use comment section for such short answers. Thanks!
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.

Comments

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.

1 Comment

I'm getting the below error Traceback (most recent call last): File "C:\Python34\lib\runpy.py", line 171, in run_module_as_main "main", mod_spec) File "C:\Python34\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Python34\Scripts\pip.exe__main_.py", line 5, in <module> ImportError: cannot import name 'main'
0

If you are using Visual Studio Code, just try to reopen the vscode code editor since it does not save the changes properly.

Comments

-1

import openpyx1

ModuleNotFoundError: No module named 'openpyx1'

Why?! I got the following enter image description here

that confirms (?) that the module is installed ...

3 Comments

It looks like you are posting a question. But by using an answer. It is not the correct way to proceed because instead of helping people, your answer is disturbing.
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.