Home > Net >  Can't use cx_Freeze on my Windows 10 Machine
Can't use cx_Freeze on my Windows 10 Machine

Time:10-01

I am building a python script that I want to compile to a .exe file for anyone to be able to run. I'm attempting to follow the guide on this other question, and I instantly ran into issues.

I'm currently developing on Windows 10 through the use of VSCode (I've also tried this through Pycharm to the same issue). I successfully have installed cx_Freeze to the point where when I try to install it again I get Requirement already satisfied:

PS E:\code\scorekeeper> py -m pip install cx_Freeze
Requirement already satisfied: cx_Freeze in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (6.8)
Requirement already satisfied: cx-logging>=3.0 in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (from cx_Freeze) (3.0)
Requirement already satisfied: importlib-metadata>=4.3.1 in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (from cx_Freeze) (4.8.1)
Requirement already satisfied: zipp>=0.5 in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (from importlib-metadata>=4.3.1->cx_Freeze) (3.5.1)

The issue is, the Pylance plugin I have in VSCode shows an error on the import saying that "Import "cx_Freeze" could not be resolved".

And as expected, when I try to run the script, I get this error:

PS E:\code\scorekeeper> & e:/code/scorekeeper/.venv/Scripts/python.exe e:/code/scorekeeper/setup.py
Traceback (most recent call last):
  File "e:\code\scorekeeper\setup.py", line 1, in <module>
    from cx_Freeze import setup, Executable
ModuleNotFoundError: No module named 'cx_Freeze'

Anyone have any ideas on what's going on here?

CodePudding user response:

The problem was that I was not in an integrated terminal using the .venv file in the project, because windows had errored when it tried to set the .venv as the active terminal due to Execution policies. Once I gave the terminal permissions to run scripts and re ran the activate it was able to install the package.

It had installed the package to the python root PATH, but was using the interpreter in the .venv folder in the project.

  • Related