Question

My script is working fine if I run it as Python from the command line. I have converted the script to an .exe and am facing an issue with xlswrite. Below is the error output:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec code in m.__dict__
  File "loader.py", line 5, in <module>
ImportError: No module named xlsxwriter

I have used this video to create the .exe for my Python script.

How should I fix the import error?

Was it helpful?

Solution

I have only used cx_freeze a few times and was successful using these steps. You were possibly missing something in this. First, create a setup.py like so:

from cx_Freeze import setup, Executable
import sys

exe = Executable(
    script="yourmodule.py",
    base="Win32GUI",
    )

setup(
    name = "desiredname",
    version = "1",
    description = "example program",
    executables = [exe]
    )

Before running this, make sure that you have all non-default (built-in) modules and the setup.py file in the same folder as the yourmodule.py file. Then from the command line, run python setup.py build.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top