-1

PROBLEM SOLVED. the issue was with jaraco module, that i used for clipboard manipulation, i used pyperclip instead.

I made a python app with tkinter that works fine, but I wanted to make an exe from it so it's user friendly in windows. I used cx_Freeze library for that, that works fine too, but not always.

When creating the exe using cx_Freeze you can specify base parameter, if you give none that will open 2 windows, cmd window and a GUI window for your app. To get rid of the cmd window you can specify "Win32GUI" as base parameter for cx_Freeze.

This ignores the cmd window and just opens the GUI, it seems to be working, but not always. Sometimes opening the exe file will start the proccess but no GUI will show. Opening cmd and going to the directory of your exe and starting it from there will actually show the GUI and fix the problem untill you restart your pc (you can open the app without cmd with everything working untill restart)

It seems that as long as cmd window is in your ram, the GUI will show, otherwise it "doesn't know" and fails to show GUI.

The code can be found here: https://github.com/GrishaDev/ClipMagic

clip.py is the entire app

setup.py is the file used with cx_Freeze to get exe of the app, that's where you specify base parameter and such.

the piece of code where the problem most likely is (setup.py):

import sys
from cx_Freeze import setup, Executable
# import os
# os.environ['TCL_LIBRARY'] = "C:\\Users\\Grisha\\AppData\\Local\\Programs\\Python\\Python35\\tcl\\tcl8.6"
# os.environ['TK_LIBRARY'] = "C:\\Users\\Grisha\\AppData\\Local\\Programs\\Python\\Python35\\tcl\\tk8.6"
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(name="clipmagic",
      version="1",
      description="Extended clipboard",
      options={'build_exe': {'includes': ["jaraco", "tkinter"], 'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
            'icon.ico',
         ]}},
      executables=[Executable("clip.py", base=base, icon='icon.ico')])

#"Win32GUI"

Thanks!

hey
  • 3
  • 9
  • Please do not link to code on another site. Instead, create a [mcve] and include it directly in your question. – Bryan Oakley Sep 13 '18 at 18:26
  • @BryanOakley i did that to not make the question look giant with entire code, and github is great source to see code, i will include my setup.py here since its smaller. – hey Sep 13 '18 at 18:39
  • 1
    We don't want "entire code". We want a small [mcve] created just for this question. And github is _not_ a great source to see code _for questions_, since the branch you link to may get updated or removed over time, rendering the question useless. – Bryan Oakley Sep 13 '18 at 18:40

1 Answers1

0

Looking at the README.md in your code repository, you are using the current version of cx_Freeze, which is 5.1.1. In this version, the included modules are in a subdirectory lib of the build directory. The manually added DLLs apparently need to be moved there as well. See this answer.

Try to make the following change to your setup.py script:

options={'build_exe': {'includes': ["jaraco", "tkinter"], 'include_files':[
    (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join('lib', 'tk86t.dll')),
    (os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), os.path.join('lib', 'tcl86t.dll')),
    'icon.ico',
    ]}},
jpeg
  • 2,372
  • 4
  • 18
  • 31
  • Yes but in `build`, where `build` is the build directory. To my opinion they should be placed in `build/lib`. – jpeg Sep 13 '18 at 18:39
  • I don't quite understand how to include it in build/lib place, i tried the following: (os.path.join('lib', os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'))) instead of the previous, but it still puts the dll's to just build/ – hey Sep 13 '18 at 19:04
  • @hey I edited my answer to explain how I would do it. – jpeg Sep 13 '18 at 19:12
  • thx, i just did like your example, restarted my pc and it doesn't work, i can literally see the GUI appearing for half a second and it's gone, but running in processes – hey Sep 13 '18 at 19:17
  • Then I don't see how I could help you further untill you've provided a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) as advised by @BryanOakley, sorry. – jpeg Sep 13 '18 at 19:21
  • thats just the setup.py, you saw it. i inluded it as screenshot in my question anyway.. Thanks for helping though, hopefully will find solution soon – hey Sep 13 '18 at 19:28
  • You also need to create a minimal application with tkinter showing the behavior you have reported and post the code in your question. And please copy and paste the code as text instead of using a screenshot, I don't see why this shouldn't work in SO, it is the desired behaviour. – jpeg Sep 13 '18 at 19:40
  • hey, i am looking again into that, and it seems to be issue with the code of the app it self, i compliled other tkinter apps, and they work fine. I am using multi threading in my app, to handle the GUI and usage of hotkeys listeners in my app, could this cause issues? If you could please take a look at my code again here: https://github.com/GrishaDev/ClipMagic/blob/master/clip.py Also i am using python 3.5. It will really help, thx. – hey Sep 18 '18 at 14:41
  • I think i fixed i t! Atleast for now its working. THE ISSUE: it was problem with jaraco module, i used pyperclip instead for clipboard usage, and it seems to be working all time now, did 2 restarts and it's working as supposed. – hey Sep 18 '18 at 15:26
  • Sounds great! So it seems that successively adding components starting from a minimal example was indeed the key here as well. – jpeg Sep 18 '18 at 18:31