Bon Voyage

MacOS에 Homebrew로 python3 설치하기 본문

설치

MacOS에 Homebrew로 python3 설치하기

nangkyeong 2019. 7. 13. 18:36

 

1. brew 명령으로 python3을 설치하자

brew install python3

아래의 안내문이 나온다

==> python
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python

설치된 경로는 /usr/local/bin/python3
아직 버전이 정해지지 않은 상태의, 3버전을 각각 가리키는 심볼릭 링크들 ('python', 'python-config', 'pip'등)이 /usr/local/opt/python/libexec/bin 경로에 설치되어 있음
이후 패키지를 추가설치하려면 pip3 install 패키지이름
pip3 명령으로 설치되는 경로는 /usr/local/lib/python3.7/site-packages

 

2. python명령어로 3버전을 쓰기 위해 bash_profile에 PATH를 설정

sudo vim ~/.bash_profile

위에서 알려 준대로 버전이 지정되지 않은 심볼릭 링크들이 있는 경로로 PATH를 지정해주자
(참고: i를 입력해 insert 모드로 변경한 후 작성이 가능하다)

export PATH=/usr/local/opt/python/libexec/bin:$PATH

작성후엔 esc 를 누른 후 :wq를 입력하고 enter

reboot없이 수정한 내용을 바로 적용하기 위해 source 명령어 수행

source ~/.bash_profile

그다음 python 명령어를 날리면 python 3 버전이 나오는 것을 확인할 수 있다 !

$ python
Python 3.7.4 (default, Jul  9 2019, 18:13:23) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

 

 

 

참고한 URL들
https://dejavuqa.tistory.com/132
https://medium.com/@arafat.azam/installing-python-with-brew-in-mac-properly-203db905aae9

Comments