Skip to content

Instantly share code, notes, and snippets.

@matangover
matangover / Python native libs on macOS with M1.md
Last active April 9, 2024 18:12
Allow Python on macOS M1 to import native libraries installed using Homebrew

Your Problem

  1. You are using Python on macOS M1 (or M2, etc) and are trying to install a Python library which uses a native library.
  2. You install the Python library (e.g. using pip) and the native library (using Homebrew).
  3. You get an error saying that the native library cannot be located even though it's installed using Homebrew.

Example: You are trying to use e.g. pyfluidsynth. You've installed pyfluidsynth with pip, and also ran brew install fluidsynth. However, import fluidsynth still gives an error:

ImportError: Couldn't find the FluidSynth library.
@matangover
matangover / README.md
Last active June 4, 2023 01:20
Easily open files from Python tracebacks in iTerm2 directly in your editor
  1. In iTerm2, go to Settings -> Profiles -> Advanced -> Smart Selection -> Edit
  2. Click + to add a rule with the following values:
    • Notes: Python traceback
    • Regular Expression: File "(.+)", line ([0-9]+), in .+
    • Precision: Very High
  3. Click Edit Actions... and add an action to open in your editor. For example, if you use VS Code, add an action with the following values:
    • Title: Open in VS Code
    • Action: Run Command...
  • Parameter: /usr/local/bin/code -r -g "\1":\2
@matangover
matangover / await_checker.py
Last active March 6, 2023 20:30
Custom pylint checker to verify all Python 3.5+ "async" functions are immediately awaited
"""Checker for non-awaited async function calls."""
import six
import astroid
from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker
def register(linter):
@matangover
matangover / Compiling Python with custom OpenSSL on Heroku.md
Last active June 14, 2020 19:24
Instructions for compiling Python with custom OpenSSL on Heroku

Prepare a dyno for compilation with the latest OpenSSL

  1. Create a one-off Heroku app (or use an existing one) for the compilation.

  2. Set the app to use the Python buildpack with OpenSSL 1.0.2g

    heroku buildpacks:set https://github.com/yuvadm/heroku-buildpack-python-openssl-1.0.2.git -a myapp
    
  3. Run a one-off dyno to do the compilation:

@matangover
matangover / heroku_python_custom_openssl.patch
Last active April 5, 2016 15:47
Compile Python for Heroku with custom OpenSSL.
--- a/setup.py
+++ b/setup.py
@@ -788,11 +788,9 @@ class PyBuildExt(build_ext):
depends=['socketmodule.h'],
libraries=math_libs) )
# Detect SSL support for the socket module (via _ssl)
- search_for_ssl_incs_in = [
- '/usr/local/ssl/include',
- '/usr/contrib/ssl/include/'
- ]