Install Python In Mac Os

Okay, best for me, anyway. In some ways, setting up Python isn’t terribly hard. You can just download an installer from Python.org and be done with it. Or download Anaconda or another distribution like it. But there are a ton of reasons that might not work for you, and doesn’t for me.

My Go-To Toolchain

For most Unix systems, you must download and compile the source code. The same source code archive can also be used to build the Windows and Mac versions, and is the starting point for ports to all other platforms. Download the latest Python 3 and Python 2 source. Jul 02, 2021 How to Install Python- Here is the instructions on how to download Python and install python on windows, ubuntu, linux, mac. Python installation made easy with this python tutorial. Python for Mac OS X. Python comes pre-installed on Mac OS X so it is easy to start using. However, to take advantage of the latest versions of Python, you will need to download and install newer versions alongside the system ones. The easiest way to do that is to install one of the binary installers for OS X from the Python Download page. Installation on OS X. To install frameworks Python on OSX, download it from the main Python website and follow the installation steps. On the default mac. If the Terminal prints “Python 2.7.3 where the exact numbers are different, directly move on to step #5.” For some reason, you want to get the current version of Python, leave it to Homebrew! It automatically works on the latest Python tools on MAC. For installing the latest version of Python, type: $ brew install python.

Updated python, virtualenvwrapper, and VSCode. That’s the name of the game. For the last year and a half or so I’ve been mostly developing on Windows, but I’m back on a Mac and installing a development environment there for the first time in a while, and there are some oddities to work through there.

1 – Python

First you’ve got to get an up-to-date python 2.7, and possibly 3.x as well. MacOS always ships with an old python installed in /usr/bin – as of this writing, Mac OS 10.13.6 is the latest, with Python 2.7.10. My preferred way to do this is:

  1. Install homebrew: https://brew.sh/
  2. brew install [email protected]
  3. brew install python

Install Python In Mac Os X

This will get you a shiny new up-to-date python at /usr/local/bin, as well as a python3. If you want, you can just install python3 and point the /usr/local/bin/python symlink at that, but I think it’s probably not ideal – it might break other things on the system that expect python to mean 2.7.

This is soft of where virtualenvs come in – make python behave just as you like, on a project-by-project basis

2 – virtualenvwrapper

Using python virtual environments gives a few advantages over using your system environment for everything. Most obviously, you can install only the packages your project needs, and keep track of what that list is. You can also get specific about the versions of those packages, or even of the python interpreter itself. This last bit is really useful – you don’t want to override python with python3 at the system level, but maybe you want to develop a project with python 3.x and don’t want to manually remember to use python3 for everything.

Installing virtualenvwrapper is easy:

  1. pip install virtualenvwrapper

Using it is mostly a matter of familiarizing yourself: http://virtualenvwrapper.readthedocs.io/en/latest/

But there’s a bit of a hitch here. It turns out, there are two kinds of Python on Mac – “framework builds” and not-that. The key differentiation here is that framework builds have access to GUI APIs, which is necessary for all softs of graphical things in Python. Most importantly for me, matplotlib doesn’t work outside of a framework build. Conveniently, homebrew installs framework builds by default now. Inconveniently, virtualenv doesn’t, whether or not the source binary is a framework build. So even if your system python is a framework build, the one inside my_env when you mkvirtualenv my_env won’t be.

There’s all sorts of relevant info in this thread, but this comment in particular highlights a so-far very functional solution copied below: https://github.com/pypa/virtualenv/issues/54#issuecomment-177344059

Of course, this has to be done every time a new virtualenv gets made, so to make it automatic, here’s the ~/.virtualenvs/postmkvirtualenv I’m using:

With this little hack/workaround, your not-framework-build is magically framework-ized and all GUI-requiring packages in your virtualenv will work as expected. I’m unaware of any drawbacks yet, aside from the up-front hassle.

VSCode

The last piece of this is VSCode. My typical workflow is to have the code command available on my terminal (Shift-Cmd-P>Install code command, inside vscode). When I want to work on a project, I go there in terminal, workon my_env, then code .. That is:

Install Python In Mac Os

This will launch VSCode with your virtualenv at the front of the $PATH, adopting the virtualenv’s interpreter and package list.

But there’s a bug at least as of time of writing – newly-created terminals and child processes in VSCode get created with the virtualenv at the END of the $PATH, for some reason that totally escapes me. Here’s the bug report: https://github.com/Microsoft/vscode-python/issues/2333#issuecomment-410426411

Luckily, the workaround isn’t terrible – every time you launch code with a new virtualenv, instead of it just working, you have to make the extra step of Shift-Cmd-P>Python: Select interpreter, and pick the interpreter inside your virtualenv. And make sure you pick the one with Python.app in its path, so that you’re getting the framework build that works with GUI APIs.

Another possible workaround is to put the following in your ~/.bash_profile:

By adding that, you should just about completely obviate the need for setting your python interpreter deliberately in settings.json as we do above, and bonus, all child terminals in Code will have the proper environment activated so you’ll never accidentally pip install something into the wrong environment!

Pylint for Python 3.7.0

One last note: the latest Pylint release doesn’t properly support Python 3.7.0 at this time. The workaround is to install the latest beta release with pip install --pre -U pylint astroid. This will fix the RuntimeError: generator raised StopIteration in Code when it automatically runs the linter and that fails. If you are in the habit of creating lots of virtualenvs and this is a big annoyance, you might add the line above into $WORKON_HOME/postmkvirtualenv as well, but be sure you set a reminder to remove it once the latest Pylint stable release supports 3.7.0 properly.

And that ought to do it!

Footnote: if you’re interested in my process for figuring out all the bugs with this setup, here’s an excel sheet of experiment data:

Related

Table Of Contents

  • Installation on OS X
    • Installation components
      • Installing Python
      • Source installation Dependencies
    • Using The Kivy.app

To install Kivy on OS X using pip, please follow the maininstallation guide.Otherwise, continue to the Kivy.app instructions below.

Install python in mac os sierra

Installation components¶

Following, are additional information linked to from some of the steps in themain installation guide, specific to OS X.

Installing Python¶

Homebrew¶

If you’re using Homebrew, you can install Python with:

MacPorts¶

If you’re using Macports, you can install Python with:

Frameworks¶

To install frameworks Python on OSX, download it from the mainPython website and follow theinstallation steps. You can read more about the installation in thePython guide.

Source installation Dependencies¶

To install Kivy from source, please follow the installation guide until you reach theKivy install step and then install the additional dependenciesbelow before continuing.

Homebrew¶

If you’re using Homebrew, you can install the dependencies with:

MacPorts¶

Note

You will have to manually install gstreamer support if you wish tosupport video playback in your Kivy App. The latest port documents show thefollowing py-gst-python port.

If you’re using MacPorts, you can install the dependencies with:

Frameworks¶

If you’re installing Python from a framework, you will need to install Kivy’s dependenciesfrom frameworks as well. You can do that with the following commands (customize as needed):

Install Python Mac Os 10.8

Now that you have all the dependencies for kivy, you need to make sureyou have the command line tools installed:

Using The Kivy.app¶

Note

Kivy.app is built on the current GitHub Action macOS version and will typicallynot work on older OS X versions. For older OS X versions, you need to build Kivy.appon the oldest machine you wish to support. See below.

Install Python 3.8 Mac Os

For OS X 10.14.4+ and later, we provide a Kivy DMG with all dependenciesbundled in a virtual environment, including a Python interpreter. This isprimarily useful for packaging Kivy applications.

Install Python In Mac Os

You can find complete instructions to build and package apps with Kivy.app in the readmeof the kivy-sdk-packager repo.

Install Python 3 In Mac Os

To install the Kivy virtualenv, you must:

  1. Navigate to the latest Kivy release on Kivy’s website orGitHub and download Kivy.dmg.You can also download a nightly snapshot ofKivy.app.

  2. Open the dmg

  3. In the GUI copy the Kivy.app to /Applications by dragging the folder icon to the right.

  4. Optionally create a symlink by running the following command:

    This creates the kivy binary that you can use instead of python to run scripts.I.e. instead of doing pythonmy_script.py or python-mpipinstall<modulename>, writekivymy_script.py or kivy-mpipinstall<modulename> to run it using the kivybundled Python interpreter with the kivy environment.

    As opposed to activating the virtualenv below, running with kivy will use the virtualenvbut also properly configure the script environment required to run a Kivy app (i.e. settingkivy’s home path etc.).

Using the App Virtual environment¶

The path to the underlying virtualenv is /Applications/Kivy.app/Contents/Resources/venv.To activate it so you can use python, like any normal virtualenv, do:

On the default mac (zsh) shell you must be in the bin directory containing activate to beable to activate the virtualenv, hence why we changed the directory temporarily.

kivy_activate sets up the environment to be able to run Kivy, by setting the kivy home,gstreamer, and other variables.

Start any Kivy Application¶

You can run any Kivy application by simply dragging the application’s main fileonto the Kivy.app icon.