Python Macos Catalina
- Macos Catalina Python 3.7
- Python Mac Os Catalina Version
- Uninstall Python Macos Catalina
- Python Mac Os Catalina Free
I recently upgraded to macOS Catalina and it seems to come with Python 3.7.3. All of my packages have come from the PIP installed with Python 3.7.3. I have installed Python 3.7.7 (the newest vers. In this episode, I discuss how I recently wrote a post entitled Installing the latest version of Python on Mac OS Catalina and overriding the old default pre-installed version about installing Python 3.7.7 on Mac OS Catalina with Homebrew. Python 3.7.7 was the latest version of Python that one could install.
Intro¶
Using and developing with Python on MacOS sometimes may be frustrating...
The reason for that is that MacOS uses Python 2 for its core system with pip as a package manager. When Xcode Command Line Tools are installed Python 3 and pip3 package manager will be available at the cli. When using Python2, Python3 and their package managers this way, all the packages will be installed at the system level and my effect the native packages and their dependences , this can break or lead to unwanted bugs in OS.
The right way to use python at MacOS is to use Virtual Environments for python. This way all the system related versions of python and their packages won't be affected and use by you.
Installing and configuring pyenv, pyenv-virtualenv¶
In order to use pyenv, pyenv-virtualenv without conflicting with the native MacOS python we need to add some configuration to our ~/.zshrc config (for mac os catalina) or your bash config if you are still using bash.
It's very imported to maintain the order of the configuration for the loading order
- First of all we need to include your Executable Paths. In the example we added all the common paths, including the paths for pyenv, pyenv-virtualenv. If you have any other path that you use, you can add them at the same line or create a new line below this one.
- Second to Executable Paths we will add two if statements that will check if the pyenv,pyenv-virtualenv are installed, if they are it will load them. If they aren't and you are using the same zsh or bash config it will ignore loading them
- Third is a fix for brew, brew doctor. When using this method it may conflict with brew as it uses python as well. If you run run brew doctor without the fix, it will show config warnings related to the python configuration files.
Configuration for ~/.zshrc or ~/.zprofile
After you saved your configuration the best way to load it is to close your terminal session and open it again. This will load the session with your updated configuration. There should be no errors at the new session.
This will install both pyenv and pyenv-virtualenv
Test if pyenv loaded currently
After the installation we would like to set a system level python version, you can chose the default from the list available from the pyenv
List available Python Version and find the version suited for your needs:
Install Requeued Python Version (Exmaple version 3.9.5) as a default system
Set it as global
You can install multiply versions of python at the same time.
List all installed python versions and virtual environments and their python versions
Now let's test our system Python version we set before, it should be the version you choose as Global before
So far we cleaned your system and installed and configured pyenv, pyenv-virtualenv.
How to use pyenv-virtualenv¶
Now let's understand how to use Python Virtual Environment with pyenv-virtualenv
Full documentation can be found at the original repo at git hub: pyenv-virtualenv github
We will list here some basic examples for a quick start and basic understanding
To create a virtualenv for the Python version used with pyenv, run pyenv virtualenv, specifying the Python version you want and the name of the virtualenv directory. For example,
This will create a virtualenv based on Python 3.9.5 under $(pyenv root)/versions in a folder called my-project-name
Activating virtualenv automatically for project
The best way we found to activate the virtualenv at your project is to link the projects directory to the virtualenv.
cd to the project's directory and link the virtualenv for example my-project-name virtualenv
This will activate the linked virtualenv every time you cd to this directory automatically From now you can use pip to install any packages you need for your project, the location of the installed packages will be at $(pyenv root)/versions/
Activating virtualenv manually for project
You can also activate and deactivate a pyenv virtualenv manually:
This will alow you to use multiply versions of python or packages for the same project
List existing virtualenvs
Delete existing virtualenv
or
You and your MacOS should be ready for using python the right way without conflicting any system or Xcode Command Line Tools (used by brew)
Comments
Question or issue on macOS:
I just upgraded to macOS Catalina from Mojave on my Macbook and tried to run a python3 script from terminal as follows: python3 scriptname.py
I get no response in the terminal and then error comes up : Python Quit unexpectedly with the following report: Please help me solve this or how do i downgrade to mojave as i need this to work
How to solve this problem?
Solution no. 1:
Your python is pointing to an unversioned libcrypto dylib. This is not allowed anymore. If re-installing python with home-brew doesn’t help you can try this which worked for me (found here: https://forums.developer.apple.com/thread/119429):
In 1), run brew commands sequentially:
In 2), change dir not only to /usr/local/Cellar/openssl/1.0.2t, but to the lib subdir
In 3), change dir to the /usr/local/lib before making the softlinks, so they are created in the /usr/local/lib
In 3) back up the current links, such to be safe
Macos Catalina Python 3.7
So overall, the steps were:
Solution no. 2:
Python Mac Os Catalina Version
Works for me, but the solution was easier:
Remark: openssl version can be different
Uninstall Python Macos Catalina
brew install openssl
sudo ln -s /usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib /usr/local/lib/libssl.dylib
sudo ln -s /usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.dylib /usr/local/lib/libcrypto.dylib