Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cx_Freeze encodings for creating macOS application

I am trying to create a standalone Python3 macOS application including tkinter and selenium by using cx_Freeze. There are three files in my project:

  • tkinter_tab3.py (contains GUI)
  • user.txt (contains user info)
  • ver004.py (called from tkinter_tab3.py and executes tasks)

I created the following setup.py file with tkinter_tab3.py being the file to be turned into the executable:

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ['encodings'], excludes = [])
includefiles = ['user.txt', 'ver004.py']

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('tkinter_tab3.py', base=base, targetName = 'suprbotcho')
]

setup(name='suprbotcho',
      version = '1.0',
      description = 'test',
      options = dict(build_exe = buildOptions),
      executables = executables)

However, when I run $python3 setup.py build then click on the created executable, I receive this error back in the terminal:

Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

In addition, when I run $python3 setup.py bdist.mac and $python3 setup.py bdist.dmg, I receive the following error:

build/suprbotcho-1.0.app/Contents/MacOS/lib/numpy/core/lib/libnpymath.a(npy_math.o):
error: can't copy 'build/suprbotcho-1.0.app/Contents/MacOS/lib/numpy/core/lib/libnpymath.a(npy_math.o):': doesn't exist or not a regular file

I do not understand where I am going wrong because I have read other posts about the encodings problem however I found no progress after trying out the posted solutions.

Here are the imports for each python file:

tkinter_tab3.py

from tkinter import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import numpy as np
import time
from datetime import datetime
from threading import Timer
from ver004 import SuPrBoTcHo, InIt_UsEr

ver004.py

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import numpy as np
import time
from datetime import datetime
from threading import Timer
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException

If I could get help on fixing this particular problem, that would be great. If you have any particular questions, feel free to let me know.

(python version: 3.6.3)

like image 770
Julian Rachman Avatar asked Dec 12 '17 04:12

Julian Rachman


1 Answers

I had the same problem.

The solution was to upgrade cxfreeze to the latest version, i.e do the following steps-

pip install -U cx_Freeze==6.0.b1
like image 189
shreyashag Avatar answered Sep 24 '22 19:09

shreyashag