1

I am not finding a specific topic on this issue with the setup file for cx_Freeze. I am trying to create an exe for my program but something is not wright with the distutils. I am not able to locate an update whl for this library so I am not sure if there is a known fix for this.

The program works fine without error.

Does anyone know why this issue exist. Please note I am not able to use pip from inside my work network so I have to do everything with whl, tar.gz' and egg files to install libraries. This is why I am trying to find an updated whl file for distutils.

My setup.py file.

from cx_Freeze import setup, Executable

base = None    

build_exe_options = {'packages': ['idna',
                                  'json',
                                  'tkinter',
                                  'operator',
                                  'clipboard',
                                  'matplotlib',
                                  'tkinter.ttk ',
                                  'matplotlib.pyplot',
                                  'matplotlib.backends.backend_tkagg'],
                     'include_files': ['tracker1.json', 'tracker2.json']}

setup(
    name='<NAME>',
    options={'build.exe': build_exe_options},
    version='<0.2>',
    description='<some random desc>',
    executables=[Executable('MAIN.py', base=base)]
)

The error:

"C:\Users\user_name\Desktop\Python 3.6.2\python.exe" "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_setup_runner.py" "C:\Users\user_name\Desktop\Python Work Projects\GATE\setup.py"
Testing started at 2:55 PM ...
Traceback (most recent call last):
running pycharm_test
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_setup_runner.py", line 26, in <module>
    exec (fh.read(), globals(), locals())
  File "<string>", line 21, in <module>
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
    distutils.core.setup(**attrs)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\dist.py", line 972, in run_command
    cmd_obj = self.get_command_obj(command)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\dist.py", line 847, in get_command_obj
    cmd_obj = self.command_obj[command] = klass(self)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\setuptools\__init__.py", line 147, in __init__
    _Command.__init__(self, dist)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance
Mike - SMT
  • 14,784
  • 4
  • 35
  • 79
  • Which version of `cx_Freeze` are you using? – jpeg Feb 19 '19 at 07:39
  • And which command do you actually run to invoke the setup script? One more thing: the `options` dictionary key should read `'build_exe'`, not `'build.exe'`. – jpeg Feb 19 '19 at 12:20
  • @jpeg hey thanks for the comments. I have used build.exe before and it worked fine. Also I am using the latest released version [cx_Freeze 5.1.1](https://pypi.org/project/cx_Freeze/) from the PyPi site. There is a pre release version but I tend to only use full release versions to avoid issues. – Mike - SMT Feb 19 '19 at 15:57
  • As far as using `build.exe` is concerned: according to what I tried, one can invoke the setup script without errors, but it does not work in the sense that no options are passed to the `build` command then. As far as using `cx_Freeze` 5.1.1 is concerned, that's fine. I was asking because Python 3.6 support has been introduced with `cx_Freeze` 5.0.1, if you would have been using an earlier version it could have been a compatibility issue with `cx_Freeze`. – jpeg Feb 19 '19 at 16:11
  • Why do you insist on having the `matplotlib` tag? I really don't see the relevance in your question. – jpeg Feb 19 '19 at 16:15
  • @jpeg 'matplotlib' has caused other issues with building an exe file for me and could be related to this problem. Its possible the dependencies might be part of the problem. – Mike - SMT Feb 19 '19 at 16:21
  • I agree with the first half of your first sentence, but disagree with the rest... anyway we can leave this open at least until the solution to your issue becomes clear :-) – jpeg Feb 19 '19 at 16:27
  • Anyway I hardly believe that the setup script you've posted works correctly with `cx_Freeze` 5.1.1 if your `MAIN.py` actually uses `tkinter` and `matplotlib` and that the executable produced runs without errors on another machine. 1) correct `build_exe` as mentionned above; 2) add `'numpy'` to the packages list, see [this question](https://stackoverflow.com/q/10005533/8516269); 3) change `base` for Windows and tell `cx_Freeze` how to include the TK/TCL DLLs, see [this answer](https://stackoverflow.com/a/52811346/8516269) for a working example using `tkinter` – jpeg Feb 19 '19 at 16:49

3 Answers3

0

Try to update setuptools using e.g. setuptools‑40.8.0‑py2.py3‑none‑any.whl from Gohlke's Windows binaries See also TypeError: dist must be a Distribution instance.

jpeg
  • 2,372
  • 4
  • 18
  • 31
  • Unfortunately I cannot download the whl in the link. My work firewall wont let me. – Mike - SMT Feb 19 '19 at 16:46
  • Well... is it an option that you download it with another machine in another network and mail it to your work account (if the firewall lets you) or take it on a USB stick (if the company policy lets you)? – jpeg Feb 19 '19 at 16:53
  • Nope. The firewall deletes all zip files and anything that can be considered code and also USB ports are all disabled. It is frustrating. I am building this application for work however work wont allow me to download the files I need lol. – Mike - SMT Feb 19 '19 at 16:54
  • Sounds really frustrating, I don't know how to help further. By the way the resource I linked terms itself unofficial but is a widely used one, one very often come across links to it; we are also using these wheels in the company I'm working for, for example. – jpeg Feb 19 '19 at 16:58
  • From the windows binary link? – Mike - SMT Feb 19 '19 at 17:00
  • Yes, from Gohlke's Windows binaries. – jpeg Feb 19 '19 at 17:04
  • I did manage to fix the issue and get my plot working as well in the application. So the main issue was how I was trying to execute the build. The secondary issues were due to missing imports. I guess `'numpy.core._methods'` and ` 'numpy.lib.format'` need to be explicitly imported form even though I do not use numpy directly in my `py` file. After adding some `os.environ[]` for tcl and tk libraries and the other imports for the build its compiled and executed without an issue. – Mike - SMT Feb 19 '19 at 18:17
0

After a lot of digging and dealing with several errors after I got the file to compile to an exe I fixed my issue.

The larger portion of the problem was related to the setup.py. I had to add a few things to make it all compile properly.

new setup.py file:

from cx_Freeze import setup, Executable
import os
base = "Win32GUI" # this lets the exe run without the console popping up.

# I had to add these 2 in order for tkinter to compile properly
os.environ['TCL_LIBRARY'] = r'C:\Users\user_name\Desktop\Python3.6.2\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\user_name\Desktop\Python3.6.2\tcl\tk8.6'

# eventhough numpy is not part of my main imports in my MAIN file I still needed to 
# provide 'numpy.core._methods' and 'numpy.lib.format' in the packages list for 
# my plot to work. I am assuming it is because `matplotlib` is using `numpy` somewhere.
build_exe_options = {'packages': ['numpy.core._methods',
                                  'numpy.lib.format',
                                  'idna',
                                  'json',
                                  'tkinter',
                                  'operator',
                                  'clipboard',
                                  'matplotlib',
                                  'tkinter.ttk',
                                  'matplotlib.pyplot',
                                  'matplotlib.backends.backend_tkagg'],
                     'include_files': [r'tracker1.json',
                                       r'tracker2.json',
                                       "tcl86t.dll",
                                       "tk86t.dll"]}
# On jpeg's advice I changed build.exe to build_exe though I am not sure what the change was for.
setup(
    name='<CCC>',
    options={'build_exe': build_exe_options},
    version='<0.2>',
    description='<CCC - Copy Count Chart!.>',
    executables=[Executable(r'C:\path\MAIN.py', base=base)]
)

After that I had to run the build command in the CMD or I would end up getting errors in my IDE console.

I am not sure why but it seams it is required to use the Command Prompt to rune the setup.py file or else it just wont work.

Here is the command if anyone else needs it:

python setup.py build

Keep in mind you may need to use a complete file path to work with the setup file. I had to the way my working directory was set up by using the below command:

python "C:\Users\user_name\Desktop\Python Work Projects\PROJECT\setup.py" build
Mike - SMT
  • 14,784
  • 4
  • 35
  • 79
0

I had a similar issue that was fixed by adding import setuptools to the top. I think it corrects some of the imports in cx_Freeze, but I'm not sure if it's related.

import setuptools
from cx_Freeze import setup, Executable

...

This also worked without adding 'numpy.core._methods', 'numpy.lib.format'.

Frank Vel
  • 1,202
  • 1
  • 13
  • 27