본문 바로가기

Python/[Know How] 파이썬 공부

맥에서 python, pip 버전 변경하기

안녕하세요. 카이랏입니다.

 

파이썬은 많은 버전들이 있고 거기에 가상환경까지 있기에 혼란스러울 때가 많습니다.

이에 이번에는 터미널에서 파이썬을 버전을 변경하는 방법을 알아보고자 합니다.

 

먼저 어떤 버전의 파이썬이 설치되어 있는지 확인합니다.

 

ls -l /usr/local/bin/python*

 

또한 어떤 버전의 pip 가 설치되어 있는지 확인합니다.

 

ls -l /usr/local/bin/pip*

 

현재 내가 사용하는 파이썬의 버전을 확인합니다.

 

python -V

 

현재 내가 사용하는 pip의 버전을 확인합니다.

 

pip3 -V

 

내가 사용할 python 명령에 맞는 파이썬 버전을 입력하여 변경합니다.

 

ln -s -f /usr/local/bin/python3.11 /usr/local/bin/python

 

내가 사용할 pip 명령에 맞는pip 버전을 입력하여 변경합니다.

 

ln -s -f /usr/local/bin/pip3.11 /usr/local/bin/pip3

 

마지막으로 내가 의도한 버전으로 명령어들이 변경되었는지 확인합니다.

 

python -V
Python 3.11.3

pip3 -V
pip 23.0.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)

 

이렇게 확인되면 됩니다.

 

만약 pip3 명령어의 버전 변경이 잘 되지 않는다면

 

where pip3

 

입력을 한 다음 폴더의 위치가 만약 /usr/bin/pip3 라고 나오는 경우는 파이썬을 다시 설치하도록 합니다.

설치 명령은 다음과 같습니다.

 

brew reinstall python@3.11

 

이 후 다시 where pip3 명령어를 통해서 폴더의 위치가 /usr/local/bin/pip3 에 있는지 확인된다면 이후로는 위의 명령어 버전 변경을 할 수 있습니다.


 

Hello. This is Kairat.

 

There are many versions of Python and even a virtual environment, so it is often confusing.

This time, let's find out how to change the Python version in the terminal.

 

First check which version of Python is installed.

 

ls -l /usr/local/bin/python*

 

Also check which version of pip is installed.

 

ls -l /usr/local/bin/pip*

 

Check the version of Python you are currently using.

 

python -V

 

Check the pip version you are currently using.

 

pip3 -V

 

Enter the python version that matches the python command I will use to change it.

 

ln -s -f /usr/local/bin/python3.11 / usr/local/bin/python

 

Change by entering the pip version that matches the pip command you will use.

 

ln -s -f /usr/local/bin/pip3.11 / usr/local/bin/pip3

 

Finally check that commands have been changed to the version I intended.

 

python -V
Python 3.11.3

pip3 -V
pip 23.0.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)

 

You can check like this.

 

If the version change of the pip3 command does not go well

 

where pip3

 

After inputting, if the location of the folder is /usr/bin/pip3, reinstall Python.

The installation command is:

 

brew reinstall python@3.11

 

if you use the where pip3 command again to confirm that the folder location is in /usr/local/bin/pip3, you can change the version of the above command.