Escaping from Anaconda's Stranglehold on macOS

If you teach a course that requires Python, you’ve encountered students on macOS who are trapped by Anaconda. Typically, they were told to install Anaconda in a first course on Python or data analytics. After that course is over, they discover that they can’t get an official version of Python to run.

Many of these students have not used the command line. Many do not understand the difference between a text editor and a word processor. If they ask ChatGPT for help, it responds with instructions that they do not understand and that wouldn’t work anyway. In my experience, most give up.

This post gives them a simple way to recover the ability to run an official version of Python. It requires neither commands from the terminal nor edits to files. All that’s required is to drag and drop a file.

Students who are trapped by Anaconda are not interested in the arcane details of shells and profiles. And for good reason. They have other things to learn first. With them in mind, I offer detailed instructions and don’t explain.

1. From Finder’s Go menu, Select Home

2. Click on the Column Heading “Name” to Make the ^ Symbol Point Up

When this symbol points up, the file you need to find will be close to the top.

3. Press Shift, Command, .

Click into the Finder window that shows the Home folder. Press these three keys at the same time: Shift, Command, .

Files and folders with names that start with a period are hidden by default. Pressing these three keys toggles on and off the option to display them.

4. Locate the File Named .zshrc

Finder uses a gray typeface to display names that start with a period. If this makes it hard for you to read the filenames, there are two ways to make the text bigger, hence easier to read:

a) In a Finder window, press all three keys: Command, Shift, +. (To undo this change, press Command, Shift, -.

b) Click on the Apple icon in the upper left corner of your screen; select System Settings; into the search box type “Display”; then select an option that increases the size of the display size for text.

With big text, here is the default Finder display when for the Home folder for someone named Sarah Jones:

Here is what it looks like after pressing the three keys that turn on the display option for hidden files and folders:

You may not have a folder called anaconda3. That’s ok. All that matters is that you see a file named .zshrc. If you don’t, skip to the Troubleshooting section at the end.

5. Drag .zshrc To Your Desktop

In Finder, you can drag a file to a new location by placing your cursor over the name of the file, pressing down on your mouse or trackpad and holding the press as you move the cursor over a new location, then lifting your finger to drop the file.

The video below shows several ways to move the file back and forth between the Home folder and the Desktop.

6. That’s It

If you haven’t already done so, download and run an installer from https://python.org/downloads. See the section “Managing Official Python on macOS” for some tips.

If the .zshrc file is not in your home folder, the code that Anaconda uses to take over your computer will not run, so any official Python will work as advertised.

7. Switching Back

Suppose you are taking one course where you have to use the official version of Python (and its package manager, pip), and a second course which requires that you use the Anaconda distribution (and its package manager, conda). What can you do?

Just drag the .zshrc file back and forth between your home directory and the Desktop where you hide it.

8. Can You Use Both at the Same Time?

Yes.

You don’t need to shut down a running version of official Python to start a new session with the Anaconda version, or vice versa.

All that matters is the location of the .zshrc file when you start a Python session. Moving the file has no effect on a session that is already running.

9. Will You Keep Using Both?

Probably not.

When I started learning Python in 2019, I followed the conventional wisdom and installed Anaconda on my MacBook. I soon discovered that this was a mistake. Anaconda may have advantages for some users in some circumstances, but it just got in the way when I was trying to learn.

Once I got official versions of Python running, I stopped using Anaconda and never went back.

10. What Changes When You Are Free

For the target readers of this post, here is what changes when you break free of Anaconda:


Managing Official Python on macOS

a) Installing

Always download versions marked as “macOS 64-bit universal2 installer.”

At the end, of the installation process, always double-click to run these two commands:

  • Update Shell Profile.command
  • Install Certificates.command

b) Viewing

Drag the Python.framework folder to the Finder Sidebar. This makes it easy to see the versions of Python that you have installed.

c) Deleting

When you want to delete a version of Python, select a version from the Finder display of the Python.framework folder. For example, the folder named 3.10 is a version. Press Command + Delete and authenticate by entering your password or using biometrics.

d) Starting Fresh

python3.11 and python3.12 are examples of major versions.

python3.12.4 and python3.12.5 are minor versions.

To be sure to start over from a clean slate, delete a major version of Python, then reinstall it. Delete first even if you are updating to a new minor version. For example, if you have python3.12.4 installed, delete the 3.12 folder then install python3.12.5.


Troubleshooting the Fix

Here are some reasons why you might not be able to use the fix that involves dragging the .zshrc file to your desktop, together with some suggestions about what you might do instead.

A. No .zshrc file because your software is out of date

One reason why you might not have a .zshrc file is because your version of Anaconda and macOS are out of date. In 2019, the terminal for macOS switched to a shell program called zsh. Prior to that, it used bash and injected the code it uses to take over your computer into a file called .bash-profile.

  • Use the three-key-combination to display any hidden files in your Home folder. If your software is years out of date, you may find a file called .bash_profile in your Home folder. You could try moving it to another folder, but doing so might break other programs that you have installed.

  • A better solution is to use the program called TextEdit that comes with macOS to examine and edit this file. To open .bash_profile using TextEdit, in Finder, right-click on the name of the file, then select the “Open With” option. Before you make any changes, save a backup copy of the file.

    The image below shows the code that Anaconda injected into .bash-profile back in 2019. Notice that the Anaconda code is delimited by lines that contain >>> conda and <<< conda. Look for code like this in .bash-profile. Delete the lines between any such delimiters. Because lines that start with the character # are comments, it is harmless to leave them. Leave any other code and save the file where it is, in your Home folder. This may break Anaconda, but it will let the official version of Python run.

  • The best approach is to update your version of macOS. If you are given the option to “Upgrade Your Shell to zsh”, you should agree. If you are told that zsh is your new default shell, that’s a good sign. This might be enough. Try to run an official version of Python.

  • If, after updating macOS, an official Python runs but Anaconda is broken, you could try doing without Anaconda. If you decide that you want to fix Anaconda, you should update the version you have or install a new version. Then you will have a .zshrc file in your home folder. It will have the that Anaconda injects to take over your computer. You can now follow the instructions from above to turn Anaconda on and off by moving this file.

B. No .zshrc file because you intentionally kept the bash shell

Dragging the .zshrc file out of your home folder will work only if zsh is the shell for macOS. It has been the default shell since 2019. If, after 5 years, you are still procrastinating about switching to zsh, your version of macOS is probably out of date. If you care about security, you should update macOS.

Then, if macOS is up-to-date, and you still want to rely on its out-of-date version of bash, follow the instructions from part A of Troubleshooting for editing .bash-profile.

If you are a sophisticated user who prefers some other shell to zsh, should be able to figure out how to adjust these instructions to work with your preferred shell.

C. Some other program has added commands to .zshrc

Most programs you install do not write to the .zshrc file. Besides Anaconda, the one type of program that is likely to put code there is a plugin that customizes the zsh shell. If, after moving the .zshrc file, you discover that some other program no longer works, you should use TextEdit to examine .zshrc. Make a backup copy. If there is code there that you want to run, edit the .zshrc file to remove the lines from Anaconda. Save the file to your home folder. Restore the lines from Anaconda if you want to enable it again.

D. You have added your own commands to .zshrc

The reason to move .zshrc is to keep commands that Anaconda puts there from running automatically. If you put commands that you want to run automatically into this file, you can use TextEdit or any other text editor to edit the file to remove the lines added by Anaconda but keep the lines you want to run. Save the file in its current location. Restore the deleted lines if you want to enable Anaconda again.