If you are not going to compile anything, you can also delete the include folder.Ĭongratulations, you now have a portable Python distribution! Unfortunately, you cannot do much with it as you don't have any binary programs that use it. You can delete lib/libpython3.5.dylib, lib/libpython3.5m.dylib and lib/pkgconfig as we won't be using them. Next, copy the include/ and lib/ folders to the destination. Copy the $homebrew/Python file and rename it to libpython3.5.dylib.
We are going to copy files from the Homebrew's source (I'll use the $homebrew prefix to refer to it) to build our Python distribution.įirst we are going to copy the python shared lib to our destination. Cherry pick some filesĬreate an empty folder named python3.5 somewhere (I like do it on my Desktop).
Since it is just a symlink to another symlink, we use the readlink command to find the destination. The first command shows us the location of the homebrew's python3 command.
Frameworks/amework/Versions/3.5/bin/python3 MacBook-Pro$ readlink /usr/local/Cellar/python3/3.5.1/bin/python3 MacBook-Pro $$ readlink /usr/local/bin/python3
Homebrew will install Python 3 in /usr/local/Frameworks/amework/Versions/3.5/. You can probably use the official Python installer from, although I prefer to do brew install python3 on the terminal. We are going to build our standalone distribution from Homebrew's Python distribution. Besides, I want to embed Python on another application, not create a standalone executable (although we can do it). I know that there are solutions such as py2app or cx_freeze, but I've never had much success with them previously. This blog post documents one of several possible ways of building a standalone Python distribution on OS X that you can use to embed in other applications. Since Python 3.5 we can use the embeddable Python distribution on Windows, but there's not such thing for OS X and we have to roll our own. Since this application must run on OS X and Windows, and I don't want my users to have to install Python 3 themselves, I have to include the Python interpreter with the application. I am currently working on a cross-platform Electron application that needs to make network calls to an embedded Python web server. I suggest to read the other one first and then read this one because it deals a lot with some things you may need after you compile from the source code. I've made a new blog post that shows how you can build a Python 3 distribution from the Python source code.