Fixing PyInstaller on OSX when using PySide

When using PyInstaller to package my PySide application  i had following errors in the command-line:

3513 INFO: Looking for dynamic libraries
3663 ERROR: Can not find path ./libpyside-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtGui.so)
3664 ERROR: Can not find path ./libshiboken-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtGui.so)
3670 ERROR: Can not find path ./libpyside-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtNetwork.so)
3670 ERROR: Can not find path ./libshiboken-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtNetwork.so)
3680 ERROR: Can not find path ./libpyside-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtCore.so)
3680 ERROR: Can not find path ./libshiboken-python2.7.1.2.dylib (needed by /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PySide/QtCore.so)

My application did start on my own machine but not on others where PySide was not installed. Here is a simple fix which worked for me to get my app running on another mac:

Open following file:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/depend/bindepend.py

and look for the function _getImports_macholib()… inside that function find following loop:

# Try multiple locations.
for run_path in run_paths:
    # @rpath may contain relative value. Use exec_path as
    # base path.
    if not os.path.isabs(run_path):
        run_path = os.path.join(exec_path, run_path)
    # Stop looking for lib when found in first location.
    if os.path.exists(os.path.join(run_path, lib)):
        final_lib = os.path.abspath(os.path.join(run_path, lib))
        rslt.add(final_lib)
        break

and change the loop to

# Try multiple locations.
for run_path in run_paths:
    # @rpath may contain relative value. Use exec_path as
    # base path.
    if not os.path.isabs(run_path):
        run_path = os.path.join(exec_path, run_path)
    # Fix path problems for PySide install on OSX
    if "PySide" in run_path:
        run_path = run_path.replace("../../../", "") 
    # Stop looking for lib when found in first location.
    if os.path.exists(os.path.join(run_path, lib)):
        final_lib = os.path.abspath(os.path.join(run_path, lib))
        rslt.add(final_lib)
        break

That's it, save the file and package your app. For me that fixed all other errors.

Here my setup when fixing: PySide 1.2.4 (PyPi), Qt 4.8.7 (stock binary), Python 2.7.12, PyInstaller 3.3-dev

Happy coding.

Creating a bootable USB stick from any ISO in MacOSX

Here are a few steps if you want to create a bootable USB stick:

  1. open Disk Utility and erase the USB drive with the partition tab
  2. choose "1 partition" and "free space" as file system
  3. open the Terminal
  4. find your USB stick device:

    # diskutil list
  5. and type

    # sudo dd if=/path/to/fiile.iso of=/dev/rdiskX bs=1m

Please make sure that you use the correct output device (of=/dev/rdiskX). if you choose the wrong one you could overwrite your internal disk!

Make an OS X Yosemite Installer USB

  1. Download the latest OSX Yosemite version from the iTunes store and, if not already done, place the app inside the Applicaitons folder
  2. open Disk Utility
  3. erase your USB drive and format your drive with partition layout "1 Partition" and the GUID option.
  4. close Disk Utility
  5. open your terminal and paste following code

    sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled\ 1 --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction
  6. done. reboot your machine and boot from the USB drive