Install cx_Freeze in Anaconda virtual environment – Windows

cx_Freeze is a tool to create Python executable.


  • Open Anaconda prompt. Goto Windows-icon. Type “Anaconda Prompt”. Select the suggestion shown.
  • Set the Anaconda virtual environment in the Anaconda prompt.
    • activate ch2_venv 
      • “ch2_venv” happens to be my virtual env. You choose yours.
  • then use pip to install like so:
    1. pip install cx_Freeze
    2. pip install idna
  • Create a new python file named in the current directory of your script and put the following code in it:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'C:\\ProgramData\\Anaconda3\\envs\\ch2_venv\\tcl\\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\\ProgramData\\Anaconda3\\envs\\ch2_venv\\tcl\\tk8.6'

base = None    

executables = [Executable("", base=base)]

packages = ["idna","sqlalchemy", "urllib","pyodbc"]
options = {
    'build_exe': {    

    name = "my_name",
    options = options,
    version = "0.1",
    description = 'My discription',
    executables = executables
  • Save the above file
    • Note: in the above code snippet for, I am setting TCL_LIBRARY and TK_LIBRARY paths directly. This is because I was having errors when I was trying to create an exe without it (cx_Freeze was unable to locate the tcl and tk folders). I also had to add pyodbc in the packages list as cx_Freeze was giving me error otherwise.
    • Note: in the above code snippet for, put the filename for file for which you want the exe here executables (I am having
    • Note: in the above code snippet for, packages lists all the imported packages in your python code
  • now, in the terminal, type:python build
  • If all is good, exe will be generated
  • Check the newly created folder build. It has another folder in it. Within that folder you can find your application. Run it.
Tek Shinobi
Author: Tek Shinobi

Hiya Ninjas, I am the ninja who invented the fire, wheel, science, technology and everything intelligent this humanity has ever experienced since its evolution from monkeys and germs. Actually, above is a partial list. I also was involved with the Big Bang that created this universe. What was it like before the Big Bang is so secret that if I tell you, I will have to turn you into a hobbit and force you to be my gardener. Okay. Sayonanra, Namaste Tek Shinobi

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *