Skip to main content
 

Installing PyInstaller on a Poetry project on MacOS

I'm looking to create a cross-platform executable of my commandline application. The application is using poetry as the package manager, and I'm running this on MacOS.

First we need to install PyInstaller:

$ poetry add pyinstaller --dev

Then it should be as simple as running the following:

$ poetry shell
$ pyinstaller --onefile app/app.py

Macho Libre

However, this resulted in the following error:

ModuleNotFoundError: No module named 'macholib'

macholib can be used to analyze and edit Mach-O headers, the executable format used by Mac OS X.

It’s typically used as a dependency analysis tool, and also to rewrite dylib references in Mach-O headers to be @executable_path relative.

Manually adding this dependency to the project addresses this:

$ poetry add macholib --dev

NLTK

However, now calling pyinstaller again throws up a new error:

Unable to find "nltk_data" when adding binary and data files.

NLTK is a leading platform for building Python programs to work with human language data. It provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet, along with a suite of text processing libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning, wrappers for industrial-strength NLP libraries [...].

Fortunately we can download the missing data as follows (from within the poetry shell):

$ python
>>> import nltk
>>> nltk.download()

Press the download button on the window that pops up and make sure the installation path matches the error message path.

Then fix the path to NLTK in PyInstaller according to this StackOverflow answer. To get to the right location, ask poetry:

$ poetry env list --full-path
$ cd <path>/lib/python3.7/site-packages/PyInstaller/hooks

Rerunning the pyinstaller command after this produced an executable! However it's 1.2GB, propably due to including the macholib library.

I will update this post when I've figured this out.

 

I’m looking for a macOS tool that intercepts opening URLs and let me specificy regexes and associate them with browsers, so that when I open certain links from slack they always go into my project browser. Any ideas?

 

Staying focused

If you follow this blog you will have noticed that I've commented multiple times on needless distractions that seem to have pervaded modern computing. Today, let's present a few solutions.

Firstly, when in the flow of doing deep work, watching animations delay your actions can be a source of frustration. While we can't speed up GitHub, we can speed up macOS. In the accessibility settings, check Display > Reduce Motion. This will speed up the interface and Mission Control animations. If you miss the garishness, you can turn it back off but chances are you will notice the system not getting in the way as much.

Secondly a tip for fellow Homebrew users. When you're ready to work through that difficult project tooling setup, it can be the worst time for Homebrew to decide to update it self, especially as this can take up to half a minute depending on how far behind your version is. Not now Homebrew! If you follow the instructions at Homebrew Autoupdate you can setup Homebrew to update itself in the background.

Finally, if you're using oh-my-zsh or bash equivalent, there will be a setting for it to update itself without prompting. Edit .zshrc and add DISABLE_UPDATE_PROMPT="true". I've not had any issues.

Cheers to a focused work experience!

 

Console.app happens to be the best .log file viewer I've ever used, for any logs - not just macOs system ones.

 

Making Recents more useful

Clean Recents list

So if you open Recents in the sidebar it's likely it's full of files you have no idea you recently opened. It's most likely that you didn't. We can make Recents more useful by restricting the last opened date, and make using it more convenient. This is how:

  1. Open Finder, then Recents in the sidebar.
  2. From the cog menu, select Show Search Criteria, add a criteria via the plus button.
  3. Change the filter name to Last Opened Date within last 14 days and press Save.
  4. Name it My Recents, and enable Add to sidebar.
  5. From the sidebar, drag the smart search into the dock next to the Trash.
  6. Optionally remove the recents icon from the sidebar. You can restore the item via Finder > Preferencers > Sidebar by dragging it back in.

As a bonus tip, update  the icon for the smart search (just like any other folder and app) as follows:

  1. Open /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ and search for "Recents" to find the current Recents icon, or choose an alternative.

  2. Right click on the My Recents icon in the sidebar and choose Get Info.

  3. Drag the preferred icon from the folder into the icon slot in the top left of the Get Info window.

This changes the icon in the window title, but I haven't found out how to change it in the sidebar.

 

What is up with macOS font rendering?

What is up with macOS font rendering?

The text in news is a lot blurrier than the text in messages.

 

macOS Catalina

macOS Catalina

Terminal hasn't changed much!

 

What do the macOS menu bar, a clever css filter I came across today, and a great iOS accessibility feature have in common? Grayscale makes for a quiet user experience.

 

Can’t believe the firewall is still off by default in 2019!

 

NPM global installation permission issues on macOS

I had trouble installing global npm packages, which failed due to permission errors. I don't want to use sudo as this will lead to problems later, and I don't want to set the global installation directory to a local directory, as that means other users don't have access to the packages.

As recommended by the NodeJS documentation this is best fixed by installing node via a version manager.

First, remove node which I incorrectly installed with homebrew:

brew uninstall node

Then install nvm as per the official instructions. In my case this also failed as this is a new system that doesn't have a .bash_profile yet. Hower as I wanted to install the zsh shell, I installed oh-my-zsh as per the instructions on their site.

Once zsh was installed (or you've created a .bash_profile using touch ~/.bash_profile, you can install node in a correct manner as follows:

nvm install node

Happy yak-shaving!

 

 

 

I understand why macOS Safari wants to sandbox browser extensions but please add a search option for safari extension instead of a 30 page list… @instapaper do you have a safari extension?

 

What's up with keyboard shortcuts on macos? For many system shortcuts, there's an application shortcut that does something different.

 

I’ve wondered for years why and don’t supply an update service for applications to hook into to keep themselves updated. I guess it’s a lot more complex than building an updater.

 

Fix for Google Chrome Bouncing Forever in the macOS Dock

I had the issue where it was not possible to launch Google Chrome. It would bounce in the dock forever without actually starting. Trashing the application and associated files (with Hazel) did not work.

Other people had the same problem:

The following instructions will help get Chrome back up and running.

The Fix

The solution to this issue is to remove all application settings. Start a terminal:

cd "/Users/`whoami`/Library/Application Support/Google"
mv Chrome Chrome.old
mkdir Chrome
open "/Users/`whoami`/Library/Application Support/Google"

Now start Chrome. If it starts correctly, trash the Chrome.old folder. 

Restoring the folder

If the fix did not work in your case, use the following commands to restore the original folder.

rm -rf Chrome
mv Chrome.old Chrome

Good luck!

 

macOS doesn't use a swap file when running from an external SSD

So I was seeing graphical glitches, freezes and Activity Monitor indicated memory pressure. Turns out macOS doesn't mount a swap file, as I am running from an external SSD install.

This is easily fixed. I can't believe it is a problem though.

By the way I had to change the end of line 4 (because the command in the Ask Different answer returned multiple results) to:

VM_VOLUME=$(/usr/sbin/diskutil list | grep "VM" | awk 'NR==1{print $7;exit }')

It's easy to add the launch item using Lingon X and start it with sudo ./mountvm.sh for the current session.

 

<p style="text-align: left;">There’s a great deal on for <a href="https://flyingmeat.com/store/">Acorn</a> my favourite macOS image editor.</p><p>#status </p>

 

macOS you could fix “recent” finder sidebar to actually show recent results.<p>#status </p>

 

macOS, you could add Automator actions for all the common publishing systems.<p>#status </p>

 

Updating Homebrew for macOS Sierra

If you've just upgraded to Sierra and previously had Homebrew installed you may find that it no longer works because of the stricter security feature in macOS. In order to get Homebrew back up and running you need to execute the following commands in your terminal (thanks thehitmaniptf):

sudo chown -R $(whoami) /usr/local
xcode-select --install

The first command simply gives your local user account ownership of /usr/local (where brew installs things). The second command updates the Xcode command line tools without which Homebrew cannot compile packages.

Once this is done you can successfully update Homebrew as normal, and diagnose any remaining issues:

brew update
brew doctor

After running this you will receive instructions on how to restore the permissions on /usr/local as after updating Homebrew no longer will use this path.

Update 6th Nov, 2016: When using cask you might get told to update the cask room location:

sudo mv /opt/homebrew-cask/Caskroom /usr/local

 

Traktor streaming to SHOUTcast servers using LiquidSoap

I've been using Traktor for years now as my deejaying solution and broadcasting tool. The one missing feature on the broadcasting side is that it can only stream directly to Icecast servers, lacking the ability to stream to SHOUTcast based servers. Most servers use the SHOUTcast streaming protocol which grew popular through the MP3 movement back around the turn of the century. We will setup a transcoding link to enable streaming to SHOUTcast servers.

This guide will focus on OS X but on a general level is also applicable to Windows users.

This replaces my previous guide at https://sites.google.com/site/traktorshoutcast/

Overview

We will need the do the following things:

  1. Install Homebrew, a package manager to help set things up.(OS X)
  2. Install and setup Icecast, a streaming server that will accept the Traktor stream. (aka local streaming server)
  3. Install and setup LiquidSoap, a transcoder that will connect to the local stream, and broadcast it in SHOUTcast format.
  4. Configure Traktor's broadcasting settings to point to the local streaming server.

Also useful is to keep the SHOUTcast stream (remote stream) details to connect to at hand (host, port, password).

signal flow

1) Install Homebrew

Homebrew is a terminal package manager to add / remove / update OS X software and compile it from source code for us, so we don't have to.

Homebrew installs the stuff you need that Apple didn’t.

To install, follow the directions on http://brew.sh. Currently (as of Feb 16) that says:

  1. Open a terminal window.
  2. Run /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Follow any instructions about the Xcode commandline tools.

After everything is setup you can run brew update to update your formulae, brew upgrade to upgrade to their latest versions, and brew doctor to diagnose any issues with your particular installation. Keep the terminal open for the next step.

2) Install and setup Icecast

Icecast is a streaming media server which [...] can be used to create an Internet radio station or a privately running jukebox and many things in between.

We will setup the local streaming server so that we can connect Traktor and the transcoder to it.

Install

In the terminal window you left open, run brew install icecast.

If I remember correctly, everything should go smoothly and before long you'll get a message saying it's successfully installed.

Configuration

To keep the configuration files we are about to create nicely together, create a broadcast folder somewhere (I used ~/Music/Broadcast).

I have prepared a very simple configuration file for you, download it from https://gist.github.com/svandragt/f7ecb720416a68f096a1 (right click the raw button and select Download Linked File As.. and save it as icecast.xml in the broadcast folder you just created).

You won't have to change the contents of this file, apart from the passwords.
This configuration creates a mount point on http://localhost:8000/traktor.ogg for Traktor and LiquidSoap to connect to.

Starting and Stopping the Local Streaming Server

In the terminal window, in your broadcast folder, run icecast -c icecast.xml. It should show a few warnings but no errors, and your local streaming server is now running. Stop it now by pressing ctrl+c.

3) Install and setup LiquidSoap

Our flagship is liquidsoap, a swiss-army knife for multimedia streaming, notably used for netradios and webtvs. Liquidsoap is a powerful and flexible language for describing your streams. It offers a rich collection of operators that you can combine at will, giving you more power than you need for creating or transforming streams. But liquidsoap is still very light and easy to use, in the Unix tradition of simple strong components working together.

We will install the program and setup a flow (configuration) to connect to the local streaming server, and broadcast it to the remote stream.

It should have been simple to install using brew, but unfortunately it was not. After several days of debugging here is a working set of instructions I produced.

Install

In the terminal window you left open, we will run the following commands:

  1. brew tap drfill/liquidsoap -- This enabled homebrew to install it.
  2. brew install --env=std liquidsoap --with-shout -- this installs LiquidSoap using the standard build environment with shoutcast support

Grab a drink. After a while hopefully all works fine. I noticed that LiquidSoap is now recommending OPAM to install it so you could try that if this doesn't work for you. (http://liquidsoap.fm/download.html) - I have not tried it.

Configuration

As before, I have created a very simple flow. You will need to setup one flow per destination stream so if you play at multiple radio stations / SecondLife clubs then you will need multiple flows.

Download it from https://gist.github.com/svandragt/af43c07d5842c9c429d5 (right click the raw button and select Download Linked File As.. and save it as example.liq in the broadcast folder).

This time you have to edit it, to add the remote stream details. Change the following lines to suit your purposes:

  • output_host = "example.com"
  • output_port = 8124
  • output_pass = "mypassword"

The configuration above is for broadcasting to a SHOUTcast server at http://example.com:8124 (using the password mypassword). Leave the rest of the file alone or make a copy and start experimenting LATER, see http://liquidsoap.fm/documentation.html. LiquidSoap is very powerful.

Starting and Stopping the Transcoder

In the terminal window, in your broadcast folder, run liquidsoap example.liq. It will start showing a lot of messages, and because you are not currently broadcasting also some errors. Stop it now by pressing ctrl+c.

Traktor

Start Traktor and open the Preferences menu item. Open the Broadcasting tab.

Use the following information to point to the local streaming server:

Server settings:

  • Address: localhost
  • Port: 8000
  • Mount path: traktor.ogg
  • Password: hackme (but you changed this, right)
  • Format: Ogg Vorbis, 44100 Hz, 192 kBit/s (highest quality, bottom option)

You can enter whatever you like in the Metadata Settings.

tractor broadcasting settings

In Traktor, click the broadcast button (the little attenna). It will flash because the local streaming server isn't running and therefore Traktor cannot connect to it. Whenever Icecast is running but the button is still flashing, check that the password and other connection details match.

For now, click it again to stop broadcasting.

All together now

Before you start streaming:

  1. Start Icecast and keep it running.
  2. In Traktor, click the broadcast button and confirm its not flashing.
  3. Open another terminal window / tab in the broadcast folder for the next step.

When you start streaming:

  1. Start LiquidSoap with the flow of your remote stream. Keep it running.
  2. Start deejaying!

When you are finished

  1. Stop broadcasting with Traktor.
  2. Stop liquidSoap to let the next DJ on the stream.
  3. Stop Icecast because nothing is connected to it now.

Final thoughts

I hope this helps anyone having trouble deejaying online, I enjoy it very much and if you'd like to listen to deep house / electronica, please listen to my mixes.