JupyterLab can be installed using conda or pip. For more detailed instructions, consult the installation guide. If you use conda, you can install it with.
![](/uploads/1/2/6/6/126670129/629086045.jpg)
$ pip install todoist-pythonDEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.So, I did what any of us would do and googled around looking for a guide to update my development environment, which runs on MacOS (formerly known as OS X).
To my surprise, I found only a handful of StackOverflow posts, and they pointed me to partial solutions. Here's the full story of how to set up your environment without breaking anything built into the MacOS operating system.A word to the wise: if you're looking to install Python 3 the 'right' way, skip down to that section. I will start by covering other ways that seem right but are not a good idea. Skip to the end of this article if you're short on time and just want the recommended way. What's so hard about this?The version of Python that ships with MacOS is well out of date from what Python recommends using for development. Python runtimes are also comically challenging at times, as noted. So what's the plan?
I have dozens of Python interpreters on my computer already, and I have no idea how to manage them effectively. I didn't want to download the latest release, move it into my path, and call it a day (or use brew install python3, which would do something similar). I figured it would cause breakages down the line in a really frustrating way that I wouldn't know how to troubleshoot. I thought the best path forward was to rip and replace whatever version of Python I was running to make a clear and definitive switch to the latest and greatest. What NOT to doMy first idea on how to make Python 3 the default Python on my system was to move the old version and add the new one.Now that we know what not to do, let's look at what we could do.
There are a couple options when we think about common installation patterns for applications on MacOS. Use Python 3 as the MacOS defaultPython's website has a we can download and use.
If we use the package installation, a python3 fill will be at available in /usr/local/bin/.Aliasing is a must since the Python binary stored in /usr/bin/ can't be changed. What's nice about an alias is that it's specific to our command-line shell. Since I use zsh by default, I put the following into the.zshrc file: $ echo 'alias python=/usr/local/bin/python3.7' /.zshrcIf you are using the default Bash shell, you can append this same text to your.bashrc: $ echo 'alias python=/usr/local/bin/python3.7' /.bashrcThis strategy works, but it isn't ideal for making future updates to Python. It means we have to remember to check the website and download the new files since Python doesn't include a command-line way to update.
Have Homebrew manage Python 3The project provides a free and open source package manager for MacOS that many people rely on. It gives Apple users a power similar to apt-get or yum. If you are a Homebrew user, you may already have Python installed. To quickly check, run. $ brew info pythonpython: stable 3.7.3 (bottled ), HEADInterpreted, interactive, object-oriented programming languagehttps: //www.python.org //usr /local /Cellar /python /3.7.21 ( 8, 437 files, 118MB ).## further output not included ##Okay, great!
The Homebrew maintainers have updated the default Python bottle to point to the latest release. Since the Homebrew maintainers are more dependable at updating the release than most of us, we can use Homebrew's version of Python 3 with the following command: $ brew update && brew upgrade pythonNow we want to point our alias (from above) to the copy of Python that Homebrew manages. # If you added the previous alias, use a text editor to update the line to the followingalias python= /usr /local /bin /python3To make sure the path above points to where Homebrew installed Python in our environment, we can run brew info python and look for the path information.This method, of using Homebrew to manage our Python environment, is a good starting place, and it made sense to me at the time.
What if we still need Python 2?It makes sense for anyone new to Python to begin with Python 3. But those of us who still need Python 2—for example, to contribute to a Python project that's only available in Python 2—can continue to use the default MacOS Python binary available in /usr/bin/python.
# If you need Homebrew's Python 2.7 run$ brew install python @2At any time, we can remove the aliases from our shell's configuration file to go back to using the default copy of Python on the system. Don't forget to update pip to pip3!The pip command is the default package manager specifically for Python packages. Although we changed our default Python command to be version 3, we have to alias our pip command separately if it's on the previous version. First, we need to check what version we're on. # Note that this is a capital V (not lowercase)$ pip -Vpip 19.0.3 from /Library /Python / 2.7 /site-packages /pip-19.0.3-py2.7.egg /pip (python 2.7 )To ensure we're installing packages compatible with our new version of Python, we'll use another alias to point to the compatible version of pip. Since we're using Homebrew as our package manager in this situation, we know it installed pip3 when we installed Python 3.
The default path should be the same as Python 3, but we can confirm this by asking the shell to find it. # This command reloads the current shell without exiting the session$ exec $0# Now we can look to see where pip points us$ which pippip: aliased to /usr /local /bin /pip3We can avoid using Homebrew to update pip, but that requires a much from the Python documentation.
What we should doWhen asking for a technical review of this article, gave me a warning that my solution could result in an unreliable idea of which Python is running that depends too closely on shells loading aliases. I knew Moshe was familiar with Python, but I didn't know is that he is an author of many Python tutorials as well as an upcoming book on Python development on MacOS. He helped 40 colleagues develop Python safely and consistently on MacOS systems following one core principle:'The basic premise of all Python development is to never use the system Python. You do not want the Mac OS X 'default Python' to be 'python3.' You want to never care about default Python.'
![Pip install gtts not working Pip install gtts not working](/uploads/1/2/6/6/126670129/713991964.png)
How do we stop caring about the default? Moshe recommends using to manage Python environments (for a deeper dive on configuring pyenv, ). This tool will manage multiple versions of Python and is described as 'simple, unobtrusive, and follows the Unix tradition of single-purpose tools that do one thing well.'
While other are available, the easiest way to get started is with Homebrew. $ pyenv global 3.7.3# and verify it worked$ pyenv version3.7.3 ( set by /Users /mbbroberg /.pyenv /version )The power of pyenv comes from its control over our shell's path. In order for it to work correctly, we need to add the following to our configuration file (.zshrc for me, possibly.bashprofile for you): $ echo -e 'if command -v pyenv 1/dev/null 2&1; thenn eval '$(pyenv init -)'nfi' /.zshrcWe also need to remove the aliases we used in the sections above since they would prevent using pyenv correctly. After removing them, we can confirm pyenv is managing our Python 3 version. # I start by resetting the current shell$ exec $0$ which python/Users /mbbroberg /.pyenv /shims /python$ python -VPython 3.7.3$ pip -Vpip 19.0.3 from /Users /mbbroberg /.pyenv /versions /3.7.3 /lib /python3.7 /site-packages /pip (python 3.7 )Now we know for certain that we're using Python 3.7.3 and pip will update alongside it without any manual aliasing between versions. Using Moshe's recommendation to use a version manager (pyenv) enables us to easily accept future upgrades without getting confused about which Python we are running at a given time.
Do it right from the startIf you are just getting started with Python development on a MacOS, do the necessary configurations to make sure you're using the right version of Python from the start. Installing Python 3, with or without Homebrew, and using alias will let you start coding, but it's not a good strategy for the long run.
As a simple version management solution to get you off to a good start. Moshe Zadka - Moshe has been involved in the Linux community since 1998, helping in Linux 'installation parties'. He has been programming Python since 1999, and has contributed to the core Python interpreter.
Moshe has been a DevOps/SRE since before those terms existed, caring deeply about software reliability, build reproducibility and other such things. He has worked in companies as small as three people and as big as tens of thousands - usually some place around where software meets system administration. For more discussion on open source and the role of the CIO in the enterprise, join us at.The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat.Opensource.com aspires to publish all content under a but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. Red Hat and the Red Hat logo are trademarks of Red Hat, Inc., registered in the United States and other countries.Copyright ©2019 Red Hat, Inc.
Python for Mac OS X
Python comes pre-installed on Mac OS X so it is easy to startusing. However, to take advantage of the latest versions ofPython, you will need to download and install newer versionsalongside the system ones. The easiest way to do that is toinstall one of the binary installers for OS X from thePython Download page. Installers areavailable for the latest Python 3 and Python 2 releases thatwill work on all Macs that run Mac OS X 10.5 and later.
Python releases include IDLE, Python's built-in interactivedevelopment environment. If you download and install Pythonfrom the release page, you may also need to download and installa newer version of Tcl/Tk for OS X. See theIDLE and Tkinter on OS X page formore information.
You can run a Python interpreter by double-clicking onApplications / Utilities / Terminal and typing python3 (if you'veinstalled a version of Python 3) or python (to use Python 2) inthe window that opens up. You can also launch IDLE for the Pythonversion you have installed by double-clicking its icon inthe appropriate Python version folder in the Applications folderor you can also just type idle3 or idle in a terminal window.
![For For](/uploads/1/2/6/6/126670129/856813959.png)
There are many thousands of additional Python software packagesavailable through PyPI, the PythonPackage Index. We recommend you use thepip tool to simplifyinstalling and managing additional packages. pip is includedwith Python 3.4 releases; for earlier releases, follow the pipinstall instructions.
Among the packages available through PyPI are some that arespecifically for OS X environments. Among these are:
- pyobjc which providesa bridge between Python and Objective-C, allowing you to writefull-featured native Cocoa applications in pure Python.
- py2app which allowsyou to make standalone OS X double-clickable application bundlesand plugins from Python scripts.
For more information about Python on OS X, see the mailing list and archivesfor thePython-Macintosh Special Interest Group.
Alternative Packages for Mac OS X.
- ActiveState ActivePython(commercial and community versions, including scientific computing modules).
- Enthought Python DistributionThe Enthought Python Distribution provides scientists with a comprehensive setof tools to perform rigorous data analysis and visualization.
Python and a comprehensive set of third-party packages and libraries are alsoavailable from several open source package manager projects for OS X,including:
![](/uploads/1/2/6/6/126670129/629086045.jpg)