Virtual environment for machine learning and deep learning on MacOS

Contents

Updating Anaconda or Python on macOS is tricky. But using the process explained below will make it easier. For this, I assume you have a clean system without any Anaconda or Python installation (except python 2.7 and Python 3.8.2 since they come pre-installed with macOS Big Sur). If you have already installed Anaconda or Python, uninstall them using any Mac App Cleaner. Without much delay, let's start.

Setup process

  • Install Homebrew from here or follow him. Homebrew is a package manager for macOS just like apt-get is for Debian (Linux) o pip
    is for python.
    • To install homebrew, open terminal and copy and paste the following code:
    • We will update and improve brew just to make sure everything is in place. To do that, copy paste the following code:
      • readiness update && readiness update
    • Now, we will add the homebrew directory to the PATH environment variable
      • echo ‘export PATH = ”/ usr / local / sbin: $ PATH”’ >> ~ / .zshrc
    • Exit the terminal and open it again.
  • After installing brew, its time to install python using brew and it will be very easy to update python using brew in the future if a new version comes out which we will talk about later.
    • To install Python, we will invoke the following command in the terminal:
    • After installing python, once again we will exit the terminal and reopen it so that the terminal can access the newly created python3 symlinks.
  • Now, type python3 in terminal, it will show the latest version of python3 which in this case is python 3.9.1
73785screenshot202021-01-0120at201-02-5720am-3504498
  • In fact, from Python 3.4, pip is included by default with the Python binary installer. Then, we don't need to install it explicitly. But we will run an update command to make sure pip and some other packages are up to date.
    Write the following code in the terminal:
    • pip3 installation: pip configuration tool wheel update
54126screenshot202021-01-0120at2012-44-1220am-9426183
  • Now, we will install the virtual environment, read more about the virtual environment here. In summary, creating a virtual environment will allow us to avoid installing Python packages globally, which could break system tools or other projects.
    • python3 -m pip install virtualenv
  • To create a virtual environment, select a project folder or location. In this case, we will create the virtual environment in the home directory.
  • Before we can start installing or using packages in the virtual environment, we will need to activate them. Activating a virtual environment will place the python and pip executables specific to the virtual environment in the PATH of our shell.
    • source ~ / pyenv / bin / Activate
    • python3 -m pip install – update pip configuration tool wheel
19513screenshot202021-01-0120at2012-48-2220am-5180419
  • Now, we will install the necessary machine learning and python packages to get started:
    • pip install requests jupyterlab notebook jupyter pandas numpy matplotlib seaborn scipy sklearn beautifulsoup4
  • If you need to install more packages, you can do it through pip3 install package name. Just make sure every time you do, have activated the virtual environment. That is all!

Activate the virtual environment and run the jupyter notebook

  • To simplify, I assume you have closed the terminal or rebooted your system. Open terminal and type the following:
12134screenshot202021-01-0120at201-02-520am-2284840
  • You have successfully run the jupyter notebook.

My name is Siddharth Shankar. I am an analytical professional with more than 2 years of experience in managing the day-to-day operational and technical aspects of the project, along with the compilation, data analysis and reporting. I am a detail oriented organized individual with a background in Statistics along with A certifications + Software Engineering and PC Technician. To know more visit: https://www.linkedin.com/in/Sshankar7/

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.