0

I'm trying to turn a python script into an executable on Mac with py2app. I've followed the guide on: https://py2app.readthedocs.io/en/latest/tutorial.html. I was getting this error at first:

script1: A python runtime not could (sic) be located. You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this applications Info.plist file.

so I changed my setup file according to these instuctions: How do I use py2app with Anaconda python? to include:

OPTIONS = {'argv_emulation': True,
       'plist': {
           'PyRuntimeLocations': [
            '@executable_path/../Frameworks/libpython3.6m.dylib',
            '/Users/myname/anaconda3/lib/libpython3.6m.dylib'
           ]
       }}

Now when I run ./dist/MyApplication.app/Contents/MacOS/MyApplication in terminal I get:

My-MacBook-Pro:script myname$ ./dist/script1.app/Contents/MacOS/script1
Traceback (most recent call last):
  File "/Users/myname/Desktop/script/dist/script1.app/Contents/Resources/__boot__.py", line 420, in <module>
    _run()
  File "/Users/myname/Desktop/script/dist/script1.app/Contents/Resources/__boot__.py", line 414, in _run
    exec(compile(source, script, 'exec'), globals(), globals())
  File "/Users/myname/Desktop/script/script1.py", line 10, in <module>
    from tkinter import *
  File "/Users/myname/anaconda3/lib/python3.6/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ValueError: character U+6573552f is not in range [U+0000; U+10ffff]
2018-01-29 13:56:56.818 script1[8020:593713] script1 Error

Do I have to install Tcl/Tk, or maybe Tk-devel? I found this Tkinter: "Python may not be configured for Tk", and it looks like a I may have to rebuild Python.

The script that I'm trying to into an app is this:

# coding: utf-8

# In[1]:


import os
import shutil
import csv
from tkinter import *
from tkinter.filedialog import *
from tkinter import ttk


def ask_for_file(event):
    global find_file
    find_file = askopenfilename()


def ask_for_folder(event):
    global find_folder
    find_folder = askdirectory()


def make_folders(event):
    name_list = []
    with open(find_file) as names_csv:
        readCSV = csv.reader(names_csv)
        big_list = list(readCSV)
        for sublist in big_list:
            for item in sublist:
                name_list.append(item)

    for i in name_list:
        # make folders for all names
        current_directory = os.getcwd()
        final_directory = os.path.join(current_directory, 'Kandidater', i)
        if not os.path.exists(final_directory):
            os.makedirs(final_directory)
        s# copy files to folders
        source_files = os.listdir(find_folder)
        for file_name in source_files:
            full_file_name = os.path.join(find_folder, file_name)
            if (os.path.isfile(full_file_name)):
                shutil.copy(full_file_name, final_directory)

root = Tk()

root.title("Kandidatmapper")

Button_1 = ttk.Button(root, text="Vælg liste over kandidater")
Button_2 = ttk.Button(root, text="Vælg mappe med filer der skal i mapperne")
Button_3 = ttk.Button(root, text="Lav kandidatmapper")

Button_1.pack()
Button_2.pack()
Button_3.pack()

Button_1.bind("<Button-1>", ask_for_file)
Button_2.bind("<Button-1>", ask_for_folder)
Button_3.bind("<Button-1>", make_folders)

root.mainloop()

My python version is 3.6.2 with anaconda, but writing python and python3 I get different outputs:

$ python
Python 3.6.2 |Anaconda custom (x86_64)| (default, Sep 21 2017, 18:29:43) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Can anyone help?

Bertil Johannes Ipsen
  • 1,656
  • 1
  • 14
  • 27
  • Are you running this in a virtual environment or in your global environment? – Mr. Kelsey Feb 02 '18 at 17:17
  • Global. Should I set up a virtual environment? I haven't tried that before. – Bertil Johannes Ipsen Feb 03 '18 at 22:07
  • I would try a virtual environment. That way you will isolate the python version and you can try different versions of py2app. [This answer](https://stackoverflow.com/a/46872088) says that it is an issue with 0.14 and that rolling back to 0.13 will solve it. – Mr. Kelsey Feb 04 '18 at 01:25

0 Answers0