Как установить jupiter notebook на mac
Перейти к содержимому

Как установить jupiter notebook на mac

  • автор:

Установка Jupyter и Pandas в MacOS

Это краткая инструкция по установке Jupyter Notebook в MacOS. Cразу будут установлены инструменты для аналитики данных.

Требования — у вас на Mac должен быть установлен Python + Virtualenv, если таковых нет в системе — в этой статье представлена подробная информация о том как установить Python на Mac.

В этой статье я просто напишу кратко команды для установки и настройки окружения.

1) Проверить есть ли python3 (если нет — инструкция выше)

python3 --version

2) Установка virtualenv. Для этого в терминале просто выполнить команду:

sudo pip3 install virtualenv

3) Инициализация виртуального окружения (перед выполнением команды нужно быть в дериктории вашего проекта, куда нужно установить Jupyter)

virtualenv venv -p python3 # инициализация source venv/bin/activate # активация

4) Далее последовательно выполнить команды:

pip install numpy pip install opencv-python pip install matplotlib pip install jupyterlab pip install pandas pip install pivottablejs

5) Запуск Jupyter, просто запустить в консоли команду:

Anaconda and Jupyter Notebook Install Instructions — macOS

1. Open the Terminal by clicking on the Spotlight magnifying glass at the top right of the screen, typing “Terminal” then clicking the Terminal icon.

2. Type the commands in red to go to the Downloads directory and download Anaconda3 2023.07. Only run the Intel CPU OR Apple Silicon CPU commands. Anaconda may take a few minutes to download.

~ $ cd ~/Downloads
Downloads $ curl -O https://repo.anaconda.com/archive/Anaconda3-2023.07-2-MacOSX-x86_64.sh

Apple Silicon CPU:

~ $ cd ~/Downloads
Downloads $ curl -O https://repo.anaconda.com/archive/Anaconda3-2023.07-2-MacOSX-arm64.sh

3. Type the command in red to install Anaconda. Only run the Intel CPU OR Apple Silicon CPU commands.

Downloads $ bash ./Anaconda3-2023.07-2-MacOSX-x86_64.sh

Apple Silicon CPU:

Downloads $ bash ./Anaconda3-2023.07-2-MacOSX-arm64.sh

4. Press Enter to read the license agreement. Use Space to continue to the next page.

Welcome to Anaconda3 2023.07

In order to continue the installation process, please review the license agreement.
Please, press ENTER to continue

5. Type yes to accept the license terms.

Do you approve the license terms? [yes|no]
[no] >>> yes

6. Press Enter to install Anaconda to the default location.

Anaconda will now be installed into this location:
/Users/username/anaconda3

— Press ENTER to confirm the location
— Press CTRL-C to abort the installation
— Or specify an different location below
[/Users/username/anaconda3] >>>

7. Type yes to have Anaconda update your PATH.

installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes

==> For changes to take effect, close and re-open your current shell.

If you’d prefer that conda’s base environment not be activated on startup, set the auto_activate_base parameter to false:

conda config —set auto_activate_base false

Thank you for installing Anaconda!

8. Open a new Terminal window by pressing ⌘ — n .

9. Type the command in red to verified Anaconda was installed.

~ $ python —version
Python 3.11

10. Type the command in red to update Anaconda.

~ $ conda update —all —yes

Start Jupyter Notebook

1. Type the command in red to start Jupyter Notebook.

How to Run Jupyter Notebooks on an Apple M1 Mac

You’ve probably heard a lot about the MacBook that contains the new Apple M1 chip. Quick summary: It’s fast. Like, really fast. You, a data scientist or related tech professional, may have bought one.

Disclaimer: We’ll attempt to keep this updated as best we can. These instructions are up to date as of November 30, 2020.

A white screen with a Jupyter logo in the top left corner and four folders visible.

  • If, instead, your Terminal says command not found: jupyter then you need to see if Python is even installed before you can install Jupyter. Move to step 3.

Step 3: Let’s check if Python has been installed. In the terminal, type python3 and hit Return.

White text on a black background.

  • If you see something similar Python 3.X.Y , with the >>> at the bottom, then great! That means Python 3 is installed. Go ahead and type quit() . Jump ahead to step 5.
  • If you get a command not found: python3 error, this means that you need to install Python. New Mac operating systems should have it already installed, so if you’re finding an error, make sure that there isn’t a typo somewhere. Move to step 4.

Step 4: You can install Python by going to XCode Command Line Tools. You’ll need to login with your Apple ID and follow the instructions. Note that the normal Anaconda download won’t work here, as the M1 computer isn’t 64-bit. Once you’re done, head back up to Step 3.

Step 5: If you’ve installed Python but had trouble installing Jupyter, then go to your Terminal and type pip3 install jupyter . If that doesn’t work, then head here and follow the instructions.

Fix the Jupyter kernel issue

At this point, Python and Jupyter should be installed. You want to stop your kernel from repeatedly dying.

Step 6: In your Terminal, type jupyter notebook and hit Return. Once you do, then click «New» (on the right-hand side) and open up a Python 3 notebook.

A white screen with a Jupyter logo in the top left corner and four folders visible.

  • If you’re able to run commands in your notebook – great! The tutorial is over. Skip to the bottom for a note about TensorFlow (if TensorFlow is what you care about) or feel free to check out some of our other posts, mostly about computer vision, here.

Step 7: Thanks to this link and user burakozdamar publicizing George Hotz’ YouTube video, we learned a workaround that will stop your Jupyter notebook kernel from. well, stopping.

You will need to use the Terminal and/or Finder to find a filepath in your system that ends with ipykernel/eventloops.py . (On my system, it is lib/python3.8/site-packages/ipykernel/eventloops.py , but yours may vary slightly. The important thing is that you find the eventloops.py file.) You will make one change to this file.

  • Open Terminal.
  • Type nanofilepath/ipykernel/eventloops.py where filepath should be the specific filepath that takes you to that specific eventloops.py in the ipykernel folder. Hit Enter. You should see the following:
  • Use your arrow keys to navigate to def _use_appnope() , which is the first function toward the bottom of the screenshot above. The return line is what we are going to edit.
  • In that return line, use your arrow keys to navigate all the way to the right-hand side of that line. After V(‘10.9’) , you are going to add:

and platform.mac_ver()[2] != ‘arm64’

The full line should look like this when you are done:

  • Once you have made that edit and are sure you haven’t created a typo, then hold Control and hit x to exit.
  • It will ask you to save. Press y. ThenpressReturn.

I recognize: this process is a very «do as I say and don’t ask any questions» process. If you want to know more, George Hotz excellently describes the debugging process in his video; you can jump to around where he makes the change (47 minutes, 30 seconds) here.

Note that George also edits the docstring (the text between the «»» triple quotation marks «»») to better reflect what the function is doing – checking for Apple Silicon.

Step 8: If you’ve followed the above steps, you should be good to go. I usually quit the Terminal (hold Command and press Q) because I think that, sometimes, updates won’t immediately take effect without restarting the Terminal. Make sure that it works by returning to step 6 and writing commands in your Jupyter notebook.

You should now be set up to go

Thanks for following along. I hope this is helpful. Let us know if you spot any mistakes or needed updates (use the email button on the left side of the screen) – I want to keep this as helpful as possible for people, and new technology tends to change very quickly.

If you’re next step is using OpenCV, follow our guide on how to to safely install OpenCV with your M1.

Want to use TensorFlow with your M1?

If your goal is to install TensorFlow, it isn’t officially supported yet on the M1.

However, you can create a virtual environment following the instructions here. Notice that while there are workarounds for certain TensorFlow features, other features like object_detection are not yet supported. If you learn of workarounds, let us know by emailing us.

Build and delpoy with Roboflow for free

Use Roboflow to manage datasets, train models in one-click, and deploy to web, mobile, or the edge. With a few images, you can train a working computer vision model in an afternoon.

Cite this post:

«Matt Brems.» Roboflow Blog, Nov 30, 2020. https://blog.roboflow.com/how-to-run-jupyter-notebooks-on-a-mac-m1/

Build and deploy computer vision models with Roboflow

Join over 250,000 developers and top-tier companies from Rivian Automotive to Cardinal Health building computer vision models with Roboflow.

Matt Brems

Growth Manager @ Roboflow. Previously solved data science problems across finance, education, politics, and more. Passionate about teaching and empowering others to accomplish more.

Installing Jupyter in Macbook Air M1

In this post I’m going to list the steps to install jupyter notebooks in a Macbook Air M1.

What is Jupyter notebook?

It’s an open-source web application that allows us to share and create documents that have live code, visualizations, and narrative text.

It supports over 40 programming languages (not only Python) and you can share those documents with others using Github, Dropbox, or email.

Why Jupyter if I’m a Java developer?

At the time of writing this blog post, I don’t have experience developing with Python and I decided to give it a try playing around with the language and with Jupyter notebooks.

Java is criticized for its verbosity as a programming language and Python is recommended for beginners because the learning curve is lower and in few lines of code you can achieve more.

Even that a vast majority of my experience has been working with Java, I’m curious about other programming languages and technologies that can help solve problems differently.

Installing Homebrew

Having homebrew installed on your laptop is useful because it’s a package management system that allows you to install anything that you need in your mac system.

You just have to copy-paste the following command in your terminal and execute. More information available here.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

After installing it we can update brew with the following command.

brew update && brew doctor 

Installing Python

We then install pyenv that lets us switching Python version easily.

brew install pyenv 

with the following command, we install Python version 3.9.1

pyenv install 3.9.1 

with the following command, we can add the initialization of pyenv new values into the .zshrc file, this way we don’t have to type the same command everytime we open a new terminal, in my case I use iterm2 .

echo 'eval "$(pyenv init -)"' >> .zshrc 

then we set the Python version 3.9.1 globally.

pyenv global 3.9.1 

Installing Jupyter

With the next command, we can install jupyter using pip3 that is a package management system useful to install and manage software packages written in Python.

pip3 install jupyter 

Running Jupyter

Once jupyter is installed we can run a jupyter notebook with the following command.

jupyter notebook 

And ‘voila’ we have jupyter notebook running in our Macbook Air M1 on http://localhost:8888/tree

dist files

Fixing the Jupyter kernel issue

There’s a problem with Jupyter notebook kernel that stops working in our shiny Macbook m1 laptop. A workaround is explained in this George Hotz youtube video.

We have to look for eventloops.py file in our system. To do this we can execute the following command:

find / -name eventloops.py 

Then in my case, I found the file in the following path that I opened using vi

vi /System/Volumes/Data/opt/homebrew/lib/python3.9/site-packages/ipykernel/eventloops.py 

We have to navigate to the function def _use_appnope() and the line of code to change is the return line. After V(‘10.9’), we have to add:

and platform.mac_ver()[2] != 'arm64' 

we save and close the file and the kernel should not stop anymore 🙂

As a workaround to the following problem:

Installing Python-3.9.1. python-build: use readline from homebrew python-build: use zlib from xcode sdk BUILD FAILED (OS X 11.3.1 using python-build 20180424) 
arch -x86_64 pyenv install 3.9.1 

then after installing it execute the following command in the terminal

pyenv local 3.9.1 

next step open file .zshrc and add the following line at the end of file

eval "$(pyenv init -)" 

close the terminal and open a new one, then execute:

python -V 

and you should see

Python 3.9.1 

Conclusion

In this post, we have seen how to install Jupyter notebook in a Macbook Air M1. Now it’s time to see what things we can do with Jupyter notebooks but this will be in another post.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *