개발입문/개발환경 세팅

Jupyter Notebook 에서 Pip 를 통해 패키지 설치하는 방법

haloaround 2020. 8. 19. 07:25

Pip, Conda 를 통해 Jupyter Notebook 에서 패키지 설치하는 법 

 

import sys
!{sys.executable} -m pip install numexpr
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} numpy

 

That bit of extra boiler-plate makes certain that you are running the pip version associated with the current Python kernel, so that the installed packages can be used in the current notebook.

import sys 를 통해 실행시키면 현재 파이썬 커널에서 사용하고 있는 pip 버전을 통해 실행시켜서, 설치된 패키지를 현재의 노트북에서 바로 사용할 수 있다. 

 

 

왜 이렇게 복잡할까? 

In short, it's because in Jupyter, the shell environment and the Python executable are disconnected. Understanding why that matters depends on a basic understanding of a few different concepts:

  1. how your operating system locates executable programs,
  2. how Python installs and locates packages
  3. how Jupyter decides which Python executable to use.

Jupyter 에서는 셸 환경과 실행가능한 파이썬이 연결되어있지 않기 때문이다. 왜 이런 문제가 생기는지는 아래 개념을 통해 이해할 수 있다.

  1. OS (운영체제) 가 어떻게 실행가능한 프로그램을 위치시키는지
  2. 파이썬이 패키지를 어떻게 설치하고 위치시키는지
  3. Jupyter 가 실행가능한 파이썬을 어떻게 사용하는지

 

아래 출처글을 남긴다. 파이썬이 잘 설치되어있다면 jvdp 와 유사한 결과를 출력할 것이다. 

난 시스템 환경변수 설정이라던가 마이너한 이슈가 있었지만, 그만 파기로 했다 ;ㅁ; 

 

 

출처. Jake VanderPlas's blog

https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/#The-Details:-Why-is-Installation-from-Jupyter-so-Messy?

 

Installing Python Packages from a Jupyter Notebook | Pythonic Perambulations

$PATH lists the directories, in order, that will be searched for any executable: for example, if I type python on my system with the above $PATH, it will first look for /Users/jakevdp/anaconda/envs/python3.6/bin/python, and if that doesn't exist it will lo

jakevdp.github.io