Iconfile not working with setuptools

I’m able to use setuptools to make a distributable app and everything works fine. Now I want to add an icon to the app.

My setup.py looks like this:

from setuptools import setup

OPTIONS = {
    "iconfile" : "models_and_textures/icon.icns",
}

setup( # Parameters of the program go in here
    name = "Game 2019",
    options = { # Build options go in here
        "build_apps" : {
            "include_patterns" : ["**/*.prc", "**/*.obj", "**/*.mtl", "**/*.jpg", "**/*.pnm", "**/*.png", "**/*.ttf", "**/*.egg", "**/*.otf"],
            "gui_apps" : {"Game 2019" : "main.py"},
            "plugins" : ["pandagl", "p3assimp"],
            "platforms" : ["manylinux1_x86_64", "macosx_10_6_x86_64", "win_amd64", "win32"]
        }
    }
)

I used this site: https://cloudconvert.com/png-to-icns to convert a png I have into an .icns file.

When I then run python3 setup.py bdist_apps, the app is successfully built and I can play the full game, but it doesn’t have the icon.

What could be causing this?

(I’m on macOS using Panda3D 1.10.4.1)

I don’t know about the icns option, but I believe that you can include an icon via the “icons” keyword in the options-dictionary that’s passed into the “setup” command. Like this:

setup (
    name = "My Game name",
    options = {
        "build_apps" : {
            "gui_apps" : {
                "My Game Name" : "myGameFile.py"
            }
            "icons" : {
                "My Game Name" : [
                    "icon32.png",
                    "icon512.png"
                ]
            }
        }
    }
)

More information should be available here:

2 Likes

Thank you so much, it worked!

The only thing is, now it only compiles for macOS.

The setuptools command returns this error:

python3 setup.py bdist_apps
running bdist_apps
:Icon(warning): Generating 128x128 icon by scaling down 256x256 image
:Icon(warning): Generating 48x48 icon by scaling down 128x128 image
:Icon(warning): Generating 32x32 icon by scaling down 48x48 image
:Icon(warning): Generating 16x16 icon by scaling down 32x32 image
running build_apps
:Icon(warning): Generating 128x128 icon by scaling down 256x256 image
:Icon(warning): Generating 48x48 icon by scaling down 128x128 image
:Icon(warning): Generating 32x32 icon by scaling down 48x48 image
:Icon(warning): Generating 16x16 icon by scaling down 32x32 image
Building platforms: manylinux1_x86_64,macosx_10_6_x86_64,win_amd64,win32
Gathering wheels for platform: manylinux1_x86_64
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/simple/opt, https://archive.panda3d.org/thirdparty
Collecting panda3d (from -r /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/requirements.txt (line 1))
  Using cached https://buildbot.panda3d.org/downloads/1318fd80d7fd48a84394ee86bad6a57c245206e1/opt/panda3d-1.10.4.1%2Bopt-cp37-cp37m-manylinux1_x86_64.whl
  Saved ./build/__whl_cache__/panda3d-1.10.4.1+opt-cp37-cp37m-manylinux1_x86_64.whl
Collecting numpy (from -r /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/requirements.txt (line 2))
  Using cached https://files.pythonhosted.org/packages/ba/e0/46e2f0540370f2661b044647fa447fef2ecbcc8f7cdb4329ca2feb03fb23/numpy-1.17.2-cp37-cp37m-manylinux1_x86_64.whl
  Saved ./build/__whl_cache__/numpy-1.17.2-cp37-cp37m-manylinux1_x86_64.whl
Successfully downloaded panda3d numpy
Building runtime for platform: manylinux1_x86_64
There are some missing modules: ['Numeric', 'StringIO', '__builtin__', '__svn_version__', '_manylinux', '_scproxy', '_uuid', '_winapi', 'backports.ssl_match_hostname', 'collections.Iterable', 'collections.Mapping', 'collections.MutableMapping', 'com.sun', 'com.sun.jna', 'com.sun.jna.platform', 'commands', 'compat.long', 'copy_reg', 'core.abs', 'core.max', 'core.min', 'core.round', 'cpickle', 'dummy.Process', 'dummy_thread', 'extern.six', 'fcompiler.FCompiler', 'fcompiler.has_f90_header', 'fcompiler.is_f_file', 'future_builtins', 'multiprocessing.AuthenticationError', 'multiprocessing.BufferTooShort', 'multiprocessing.TimeoutError', 'multiprocessing.get_context', 'multiprocessing.get_start_method', 'multiprocessing.set_start_method', 'netbios', 'nose', 'nose.plugins', 'nose.plugins.base', 'nose.plugins.builtin', 'nose.plugins.errorclass', 'nose.util', 'numarray', 'numpy.amax', 'numpy.amin', 'numpy.array', 'numpy.bool_', 'numpy.compat.asbytes', 'numpy.compat.asstr', 'numpy.compat.asunicode', 'numpy.compat.basestring', 'numpy.compat.bytes', 'numpy.compat.contextlib_nullcontext', 'numpy.compat.integer_types', 'numpy.compat.is_pathlib_path', 'numpy.compat.isfileobj', 'numpy.compat.long', 'numpy.compat.npy_load_module', 'numpy.compat.open_latin1', 'numpy.compat.os_PathLike', 'numpy.compat.os_fspath', 'numpy.compat.pickle', 'numpy.compat.unicode', 'numpy.core.Inf', 'numpy.core.add', 'numpy.core.all', 'numpy.core.amax', 'numpy.core.amin', 'numpy.core.arange', 'numpy.core.array', 'numpy.core.array2string', 'numpy.core.array_repr', 'numpy.core.asanyarray', 'numpy.core.asarray', 'numpy.core.atleast_1d', 'numpy.core.atleast_2d', 'numpy.core.atleast_3d', 'numpy.core.bool_', 'numpy.core.cdouble', 'numpy.core.complexfloating', 'numpy.core.conjugate', 'numpy.core.count_nonzero', 'numpy.core.csingle', 'numpy.core.divide', 'numpy.core.dot', 'numpy.core.double', 'numpy.core.dtype', 'numpy.core.empty', 'numpy.core.empty_like', 'numpy.core.errstate', 'numpy.core.fastCopyAndTranspose', 'numpy.core.finfo', 'numpy.core.float32', 'numpy.core.float64', 'numpy.core.float_', 'numpy.core.geterrobj', 'numpy.core.hstack', 'numpy.core.iinfo', 'numpy.core.inexact', 'numpy.core.inf', 'numpy.core.intc', 'numpy.core.integer', 'numpy.core.intp', 'numpy.core.isfinite', 'numpy.core.isinf', 'numpy.core.isnan', 'numpy.core.isnat', 'numpy.core.isscalar', 'numpy.core.linspace', 'numpy.core.matmul', 'numpy.core.moveaxis', 'numpy.core.multiply', 'numpy.core.ndarray', 'numpy.core.newaxis', 'numpy.core.number', 'numpy.core.object_', 'numpy.core.ones', 'numpy.core.product', 'numpy.core.result_type', 'numpy.core.roll', 'numpy.core.sign', 'numpy.core.signbit', 'numpy.core.single', 'numpy.core.sqrt', 'numpy.core.sum', 'numpy.core.swapaxes', 'numpy.core.take', 'numpy.core.transpose', 'numpy.core.ufunc', 'numpy.core.vstack', 'numpy.core.zeros', 'numpy.deprecate', 'numpy.dtype', 'numpy.expand_dims', 'numpy.eye', 'numpy.frombuffer', 'numpy.histogramdd', 'numpy.integer', 'numpy.intp', 'numpy.iscomplexobj', 'numpy.lib.i0', 'numpy.lib.imag', 'numpy.lib.iscomplexobj', 'numpy.lib.real', 'numpy.linalg.eigvals', 'numpy.linalg.inv', 'numpy.linalg.lstsq', 'numpy.linalg.matrix_power', 'numpy.ma.MAError', 'numpy.ma.MaskedArray', 'numpy.ma.filled', 'numpy.ma.getdata', 'numpy.ma.getmaskarray', 'numpy.ma.make_mask_descr', 'numpy.ma.masked', 'numpy.ma.masked_array', 'numpy.ma.nomask', 'numpy.ndarray', 'numpy.recarray', 'numpy.testing.jiffies', 'numpy.testing.memusage', 'numpy_distutils', 'numpy_distutils.command.build_flib', 'numpy_distutils.command.cpuinfo', 'numpy_distutils.cpuinfo', 'numpy_distutils.fcompiler', 'ordereddict', 'org.python.modules.posix.PosixModule', 'pickle5', 'pkg_resources.extern.appdirs', 'pkg_resources.extern.packaging', 'pkg_resources.extern.six', 'pkg_resources.extern.six.moves', 'pytest', 'scipy', 'setuptools.extern.packaging', 'setuptools.extern.packaging.utils', 'setuptools.extern.packaging.version', 'setuptools.extern.six', 'setuptools.extern.six.moves', 'setuptools.extern.six.moves.configparser', 'sitecustomize', 'testing.Tester', 'thread', 'urllib2', 'urlparse', 'win32com.shell', 'win32con', 'win32pdh', 'win32wnet', 'wincertstore']
Copying game files for platform: manylinux1_x86_64

Writing /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python
Version/Project Files/build/manylinux1_x86_64/models_and_textures/main_screen.egg.bam
Gathering wheels for platform: macosx_10_6_x86_64
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/simple/opt, https://archive.panda3d.org/thirdparty
Collecting panda3d (from -r /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/requirements.txt (line 1))
  Using cached https://buildbot.panda3d.org/downloads/1318fd80d7fd48a84394ee86bad6a57c245206e1/opt/panda3d-1.10.4.1%2Bopt-cp37-cp37m-macosx_10_6_x86_64.whl
  Saved ./build/__whl_cache__/panda3d-1.10.4.1+opt-cp37-cp37m-macosx_10_6_x86_64.whl
Collecting numpy (from -r /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/requirements.txt (line 2))
  Using cached https://files.pythonhosted.org/packages/b4/e8/5ececadd9cc220bb783b4ce6ffaa9266925d37ed41237bc23bc530ab4f3d/numpy-1.17.2-cp37-cp37m-macosx_10_6_intel.whl
  Saved ./build/__whl_cache__/numpy-1.17.2-cp37-cp37m-macosx_10_6_intel.whl
Successfully downloaded panda3d numpy
Building runtime for platform: macosx_10_6_x86_64
Copying game files for platform: macosx_10_6_x86_64

Writing /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python
Version/Project Files/build/macosx_10_6_x86_64/models_and_textures/main_screen.egg.bam
Bundling macOS app into /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/build/macosx_10_6_x86_64/Mars Lander – Akaash Thao, 2019.app
Gathering wheels for platform: win_amd64
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/simple/opt, https://archive.panda3d.org/thirdparty
Collecting panda3d (from -r /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/requirements.txt (line 1))
  Using cached https://buildbot.panda3d.org/downloads/1318fd80d7fd48a84394ee86bad6a57c245206e1/opt/panda3d-1.10.4.1%2Bopt-cp37-cp37m-win_amd64.whl
  Saved ./build/__whl_cache__/panda3d-1.10.4.1+opt-cp37-cp37m-win_amd64.whl
Collecting numpy (from -r /Volumes/iMac and MBP Files/CAMBRIDGE/ENGINEERING – 1A/Mars_Lander/Python Version/Project Files/requirements.txt (line 2))
  Using cached https://files.pythonhosted.org/packages/bd/51/7df1a3858ff0465f760b482514f1292836f8be08d84aba411b48dda72fa9/numpy-1.17.2-cp37-cp37m-win_amd64.whl
  Saved ./build/__whl_cache__/numpy-1.17.2-cp37-cp37m-win_amd64.whl
Successfully downloaded panda3d numpy
Building runtime for platform: win_amd64
There are some missing modules: ['_bisect', '_blake2', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_contextvars', '_curses', '_datetime', '_heapq', '_json', '_md5', '_multibytecodec', '_opcode', '_pickle', '_posixsubprocess', '_random', '_sha1', '_sha256', '_sha3', '_sha512', '_struct', 'array', 'binascii', 'grp', 'math', 'mmap', 'zlib']
Traceback (most recent call last):
  File "setup.py", line 11, in <module>
    "platforms" : ["manylinux1_x86_64", "macosx_10_6_x86_64", "win_amd64", "win32"]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Developer/Panda3D/direct/dist/commands.py", line 1414, in run
    self.run_command('build_apps')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Developer/Panda3D/direct/dist/commands.py", line 380, in run
    self.build_runtimes(platform, True)
  File "/Developer/Panda3D/direct/dist/commands.py", line 709, in build_runtimes
    create_runtime(appname, scriptname, False)
  File "/Developer/Panda3D/direct/dist/commands.py", line 669, in create_runtime
    self.update_pe_resources(appname, temp_file.name)
  File "/Developer/Panda3D/direct/dist/commands.py", line 463, in update_pe_resources
    pef.add_icon(icon)
  File "/Developer/Panda3D/direct/dist/pefile.py", line 669, in add_icon
    icon._write_bitmap(buf, image, size, 8)
  File "/Developer/Panda3D/direct/p3d/DeploymentTools.py", line 413, in _write_bitmap
    assert closest_diff < 100
AssertionError

It makes the build directory and creates a macOS app, but it doesn’t finish the Linux or Windows apps. It also doesn’t get round to creating a dist directory.

It’s a known bug, it’s fixed in the dev banch and will be available in Panda 1.10.5 (see https://github.com/panda3d/panda3d/issues/718)

Ah right, do you know where I can get the dev branch and can I just install/build it like the current Panda3D SDK?

In the past you could find the night builds from the download page but since the website overhaul it’s no longer the case sadly…

You can download and install Panda from the sources but it takes lots of time, see https://github.com/panda3d/panda3d/blob/master/README.md

The Dev branch is release/1.10.x

You can actually still build dev builds from the stable branch using deploy-ng by doing this in your requirements.txt:

--extra-index-url https://archive.panda3d.org/branches/release/1.10.x/opt
panda3d>=1.10.5.dev0
1 Like

Update:

If I use setuptools in the way I’ve been doing until today (no icons and using Panda3D 1.10.4.1), then everything works fine.
If I then change my requirements.txt to:

--extra-index-url https://archive.panda3d.org/branches/release/1.10.x/opt
panda3d>=1.10.5.dev0
numpy

and I use setuptools but still without icons, then again, everything works fine.

Keeping requirements.txt as above, but this time including the icons line in setup.py, setuptools no longer works and I get the same AssertionError. So it seems as though using the dev build still doesn’t solve the icons issue. I can still get an icon on macOS, but it fails when it comes to Windows and Linux.

This is the specific error message:

Building runtime for platform: win_amd64
There are some missing modules: ['_bisect', '_blake2', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_contextvars', '_curses', '_datetime', '_heapq', '_json', '_md5', '_multibytecodec', '_opcode', '_pickle', '_posixsubprocess', '_random', '_sha1', '_sha256', '_sha3', '_sha512', '_struct', 'array', 'binascii', 'grp', 'math', 'mmap', 'zlib']
Traceback (most recent call last):
  File "setup.py", line 11, in <module>
    "platforms" : ["manylinux1_x86_64", "macosx_10_6_x86_64", "win_amd64", "win32"]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Developer/Panda3D/direct/dist/commands.py", line 1414, in run
    self.run_command('build_apps')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Developer/Panda3D/direct/dist/commands.py", line 380, in run
    self.build_runtimes(platform, True)
  File "/Developer/Panda3D/direct/dist/commands.py", line 709, in build_runtimes
    create_runtime(appname, scriptname, False)
  File "/Developer/Panda3D/direct/dist/commands.py", line 669, in create_runtime
    self.update_pe_resources(appname, temp_file.name)
  File "/Developer/Panda3D/direct/dist/commands.py", line 463, in update_pe_resources
    pef.add_icon(icon)
  File "/Developer/Panda3D/direct/dist/pefile.py", line 669, in add_icon
    icon._write_bitmap(buf, image, size, 8)
  File "/Developer/Panda3D/direct/p3d/DeploymentTools.py", line 413, in _write_bitmap
    assert closest_diff < 100
AssertionError

Actually, you have to install the Dev build using pip and I the updated requirements.txt otherwise you are just shipping the new version of Panda using the old version, hence the bug is still there.

I tried this:

python3 -m pip install --pre --extra-index-url https://archive.panda3d.org/ panda3d==1.10.5.dev32

and got this error:

ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/Developer/Panda3D/panda3d.dist-info/RECORD'

Also, do I keep requirements.txt as it is or should it be different?

EDIT:
So I kept requirements.txt the same and in regards to the EnvironmentError, I just did sudo touch /Developer/Panda3D/panda3d.dist-info/RECORD, then ran the pip command again. This time it said:

Can't uninstall 'panda3d'. No files were found to uninstall.
Successfully installed panda3d-1.10.5.dev32

So I assume it worked.

I ran setuptools again and it seems to have worked. It finished producing executable apps for Windows and Linux, but I won’t know if they worked until I try them out.