You import the module
xlsxwriter into your Python program. Unfortunately, a message error comes up:
ModuleNotFoundError: No module named 'xlsxwriter'. We will explain the cause and teach you how to fix this problem in this article. Read now!
Cause of ModuleNotFoundError: No module named ‘xlsxwriter’
You want to take advantage of the
xlsxwriter module. But when you try importing it to your Python, the program stops working and delivers an error message:
ModuleNotFoundError: No module named 'xlsxwriter'.
Here is the code sample that leads to the issue:
The Python program will give you an error message like this:
import xlsxwriter ModuleNotFoundError: No module named 'xlsxwriter'
The syntax is completely correct. There is nothing wrong with your command. But the problem is that you have not installed the
xlsxwriter module in your Python.
Remember that Python does not have the built-in module
xlsxwriter. Open your computer to install this module and the
ModuleNotFoundError will vanish.
How to solve ModuleNotFoundError: No module named ‘xlsxwriter’
We have determined the cause of
ModuleNotFoundError: No module named 'xlsxwriter'. As recommended above, we will need to install it into Python. Here are all the steps to do this work:
Step 1: Open Command Prompt
The Command Prompt is where you install packages on your computer. Open the search bar and search the term: Command Prompt. After that, open this application.
Another quick way is to type Windows + R at the same time. You enter
cmd and tap on OK. The Command Prompt will show up.
Step 2: Install the xlsxwriter module into Python
pip command allows you to install packages to your computer, including
You have to input the following command in the Command Prompt:
python -m pip install xlsxwriter
xlsxwriter will be downloaded and installed on your computer.
If you fail to install
xlsxwriter due to a Permission Error, use 1 of the 2 following commands to solve the problem:
xlsxwriter with superuser’s privileges:
python sudo -H pip install xlsxwriter
xlsxwriter in the user folder:
python -m pip install xlsxwriter --user
Step 3: Import xlsxwriter into your Python program
Remember that you can check the version of xlsxwriter in your Python with the command: pip show:
python -m pip show xlsxwriter
The result will look like this:
Name: XlsxWriter Version: 3.0.3 Summary: A Python module for creating Excel XLSX files.
As the installation is completed, you can import xlsxwriter to your Python program. There will be no more ModuleNotFoundError.
Here is the syntax for importing
xlsxwriter in Python:
The importing will be successful. You will then be able to take advantage of the
xlsxwriter module to create your Python program.
Here is the code sample using
import xlsxwriter # Create a new Excel fileworkbook = xlsxwriter.Workbook('learnshareit.xlsx') worksheet = workbook.add_worksheet() # Close the excel file workbook.close()
There will be no output, as the
xlsxwriter module helps you create an Excel file and work on it right from your Python program.
In conclusion, the
ModuleNotFoundError: No module named 'xlsxwriter' occurs when you import the
xlsxwriter module while not having it installed on your computer. The solution is easy as you just need to download and install it in your Python.