ImportError: No module named xlsxwriter
Asked Answered
E

10

52

I recently downloaded the xlsxwriter version 0.6.4 and installed it on my computer. It correctly added it to my C:\Python27\Lib\site-packages\xlsxwriter folder, however when I try to import it I get the error ImportError: No module named xlsxwriter. The traceback is File "F:\Working\ArcGIS\ArcGIS .py\Scripts\Append_Geodatabase.py".

However if I try to import numpy (I can't remember what numby is, however it is located in the same site-packages folder C:\Python27\Lib\site-packages\numpy) it has no problem.

Any idea of what could be causing this issue?

Thanks for the help.

Excursion answered 9/12, 2014 at 17:29 Comment(1)
So it turns out the issue was because I was using python with ArcGIS and didn't realize there were two version of python. When I ran a sample program using Python in the Python27 folder it worked, so I just had to copy over the installed site-packages to the ArcGIS version of python as well and everything worked.Excursion
R
29

Even if it looks like the module is installed, as far as Python is concerned it isn't since it throws that exception.

Try installing the module again using one of the installation methods shown in the XlsxWriter docs and look out for any installation errors.

If there are none then run a sample program like the following:

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()

If you still have a error after that then the most likely/common issue is that you have more than one version of Python installed (for example the system Python and another one used by an IDE) and the library has been installed in one and not the other.

Riggall answered 9/12, 2014 at 20:30 Comment(1)
I developed code using the library on the Mac. The pip installed worked fine. When I tested on Windows, I was getting the same error as the OP in Cygwin. That is, the pip install on Cygwin appears to be broken. I followed the tarball install method at the link provided here, and everything works just fine. FYI.Seclusive
S
56

Here are some easy way to get you up and running with the XlsxWriter module.The first step is to install the XlsxWriter module.The pip installer is the preferred method for installing Python modules from PyPI, the Python Package Index:

sudo pip install xlsxwriter

Note

Windows users can omit sudo at the start of the command.

Swarey answered 17/12, 2015 at 10:41 Comment(0)
R
29

Even if it looks like the module is installed, as far as Python is concerned it isn't since it throws that exception.

Try installing the module again using one of the installation methods shown in the XlsxWriter docs and look out for any installation errors.

If there are none then run a sample program like the following:

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()

If you still have a error after that then the most likely/common issue is that you have more than one version of Python installed (for example the system Python and another one used by an IDE) and the library has been installed in one and not the other.

Riggall answered 9/12, 2014 at 20:30 Comment(1)
I developed code using the library on the Mac. The pip installed worked fine. When I tested on Windows, I was getting the same error as the OP in Cygwin. That is, the pip install on Cygwin appears to be broken. I followed the tarball install method at the link provided here, and everything works just fine. FYI.Seclusive
E
15

I have the same issue. It seems that pip is the problem. Try

pip uninstall xlsxwriter
easy_install xlsxwriter
Earthshaker answered 26/8, 2015 at 6:17 Comment(0)
W
5

I managed to resolve this issue as follows...

Be careful, make sure you understand the IDE you're using! - Because I didn't. I was trying to import xlsxwriter using PyCharm and was returning this error.

Assuming you have already attempted the pip installation (sudo pip install xlsxwriter) via your cmd prompt, try using another IDE e.g. Geany - & import xlsxwriter.

I tried this and Geany was importing the library fine. I opened PyCharm and navigated to 'File>Settings>Project:>Project Interpreter' xlslwriter was listed though intriguingly I couldn't import it! I double clicked xlsxwriter and hit 'install Package'... And thats it! It worked!

Hope this helps...

Windburn answered 22/5, 2018 at 0:10 Comment(2)
True, i had the exactly same problem when i start a new project. Load the old project works also for meDecillion
I'm using Anaconda Spyder and have tried every which way to install xlsxwriter. No matter how I install, using either spyder or iPython both come back as module not found during import of xlsxwriter. Next step is to uninstall anaconda all together and reinstall everythingEnsoul
P
3
sudo pip install XlsxWriter

Make sure that X and W are in uppercase.

Preclinical answered 12/6, 2021 at 8:54 Comment(1)
That shouldn't matter. Both variants should work.Riggall
B
1

I am not sure what caused this but it went all well once I changed the path name from Lib into lib and I was finally able to make it work.

Bisector answered 12/2, 2017 at 14:39 Comment(0)
P
1

I installed it by using a wheel file that can be found at this location: https://pypi.org/project/XlsxWriter/#files

I then ran pip install "XlsxWriter-1.2.8-py2.py3-none-any.whl"

Processing ./XlsxWriter-1.2.8-py2.py3-none-any.whl
Installing collected packages: XlsxWriter
Successfully installed XlsxWriter-1.2.8

Pfennig answered 14/4, 2020 at 13:35 Comment(4)
Hi, I installed xlsxwriter in Visual Studio Code but I am having exactly the same problem as the original post. It gives me the error, No module named 'xlsxwriter'. When I tried to install it again, it says it is already installed. When I run my code using IDLE, it works without any problems. I have tried all the solutions give above. Need help please, this is second day I am struggling with this. ThanksHarridan
@Harridan I installed it locally regardless of VScode, I suggest you search your system where it is located using pip.pypa.io/en/stable/reference/pip_list And then try to figure out what is the issue. note, it is not an extension in VScode, but a python package,.Pfennig
OK I will try. I vaguely know what is going on but not sure as I am new to this. It has to do with virtual environment. But I will try. Thanks.Harridan
Just tumbled across this problem. For VSCode, make sure you have a settings.json in .vscode with { "python.pythonPath": "venv/bin/python3" }Troublous
I
1

in VSCode: instead of activating your environment with script use python select interpreter from VSCode(press ctrl + shift + p) and then select your environment from the list (marked with recommended)

Idolater answered 23/5, 2022 at 23:0 Comment(0)
S
1

Using this on Raspberry Pi 4. I had a similar issue. I followed the install step:

sudo pip install xlsxwriter

None of the IDEs could find the module. I had to use Add/Remove Software under preferences in the GUI, search for xlsxwriter, select one by clicking on it and make sure the box is checked, and then click apply, then select the other one (it showed two for me) and click apply for that one. After that, it worked fine.

Sorus answered 15/12, 2022 at 12:44 Comment(0)
L
0

I found the same error when using xlsxwriter in my test.py application. First, check if you have xlsxwriter module installed or not.

sudo pip install xlsxwriter

Then check the python version you are using, The following worked for me

python2 test.py

Liverish answered 29/4, 2021 at 13:26 Comment(1)
No need to add new answers on already answered questions, especially if the answer is similar to the previous ones. Also, I suggest you quit python 2 which is deprecated for years now..Syneresis

© 2022 - 2024 — McMap. All rights reserved.