Python / PIP(Python Package Index) 사용법

Python Package Index

Python Package Index는 파이썬 패키지들이 모여 있는 저장소입니다.

The Python Package Index (PyPI) is a repository of software for the Python programming language.

pip 명령어로 패키지를 로컬 머신에 설치하고 삭제하고 업데이트할 수 있습니다.

PIP

pip는 파이썬으로 작성된 패키지 소프트웨어를 관리하는 패키지 관리 시스템입니다. 파이썬 2.7.9 이후 버전과 파이썬 3.4 이후 버전은 pip를 기본적으로 포함하고 있습니다.

pip는 [Windows PowerShell] 또는 [명령 프롬프트]에서 실행할 수 있습니다.

pip list

pip list 명령으로 현재 설치된 패키지 목록을 볼 수 있습니다. 업데이트가 필요한 패키지가 있는지도 알려줍니다.

PS C:\Users\JB> pip list
Package    Version
---------- -------
pip        21.2.4
setuptools 58.1.0
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the 'C:\Program Files\Python310\python.exe -m pip install --upgrade pip' command.

pip show package-name

pip show 다음에 패키지 이름을 넣으면, 그 패키지 정보가 출력됩니다.

PS C:\Users\JB> pip show pip
Name: pip
Version: 21.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: c:\program files\python310\lib\site-packages
Requires:
Required-by:

pip install package-name

pip install 명령으로 패키지를 설치합니다.(flake8은 작성한 코드가 코드 작성 기준에 맞는지 검토하는 패키지입니다.)

C:\Users\JB>pip install flake8
Collecting flake8
  Downloading https://files.pythonhosted.org/packages/e9/76/b915bd28976068a9843bf836b789794aa4a8eb13338b23581005cd9177c0/flake8-3.7.7-py2.py3-none-any.whl (68kB)
    100% |████████████████████████████████| 71kB 849kB/s
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in c:\users\jb\appdata\roaming\python\python37\site-packages (from flake8) (0.6.1)
Collecting pycodestyle<2.6.0,>=2.5.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/0e/0c/04a353e104d2f324f8ee5f4b32012618c1c86dd79e52a433b64fceed511b/pycodestyle-2.5.0-py2.py3-none-any.whl (51kB)
    100% |████████████████████████████████| 51kB 1.3MB/s
Collecting pyflakes<2.2.0,>=2.1.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/84/f2/ed0ffb887f8138a8fe5a621b8c0bb9598bfb3989e029f6c6a85ee66628ee/pyflakes-2.1.1-py2.py3-none-any.whl (59kB)
    100% |████████████████████████████████| 61kB 1.4MB/s
Collecting entrypoints<0.4.0,>=0.3.0 (from flake8)
  Downloading https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl
Installing collected packages: pycodestyle, pyflakes, entrypoints, flake8
Successfully installed entrypoints-0.3 flake8-3.7.7 pycodestyle-2.5.0 pyflakes-2.1.1

패키지를 업그레이드하고 싶다면 --upgrade 옵션을 붙입니다.

C:\Users\JB>pip install --upgrade flake8

pip uninstall package-name

pip uninstall 명령으로 패키지를 삭제합니다.

C:\Users\JB>pip uninstall flake8
Uninstalling flake8-3.7.7:
  Would remove:
    c:\users\jb\appdata\local\programs\python\python37-32\lib\site-packages\flake8-3.7.7.dist-info\*
    c:\users\jb\appdata\local\programs\python\python37-32\lib\site-packages\flake8\*
    c:\users\jb\appdata\local\programs\python\python37-32\scripts\flake8.exe
Proceed (y/n)? y
  Successfully uninstalled flake8-3.7.7

pip help

C:\Users\JB>pip help

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to
                              WARNING, ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
                              (a)bort).
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the
                              certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output
같은 카테고리의 다른 글
Python / 윈도우에서 pip로 설치할 때 '액세스가 거부되었습니다.' 해결하는 방법

Python / 윈도우에서 pip로 설치할 때 '액세스가 거부되었습니다.' 해결하는 방법

윈도우에서 pip로 라이브러리를 설치할 때, 다음과 같은 에러가 나면서 설치가 되지 않을 수 있습니다. ERROR: Could not install packages due to an EnvironmentError: 액세스가 거부되었습니다: 'C:\\Program Files (x86)\\Python38-32\\Lib\\site-packages\\PIL' Consider using the `--user` option or check the permissions. 해당 폴더에 적절한 권한이 없어서 발생하는 문제로, 관리자 권한으로 CMD를 실행하면 해결됩니다.

Python / 자료형 / 집합(set)

Python / 자료형 / 집합(set)

집합(set) 집합은 여러 개의 자료를 하나의 변수로 관리할 때 사용하는 자료형 중의 하나입니다. 집합 자료형은 수학의 집합과 같은 성질을 가집니다. 즉, 집합은 중복된 데이터를 가질 수 없고, 순서가 없습니다. 따라서 순서와 관련된 인덱스기호()를 사용할 수 없고, 중복 데이터를 만드는 +, *를 사용할 수 없습니다. 하지만, in, not in, len()은 사용할 수 있습니다. 집합 만들기 집합은 중괄호로 만듭니다. >>> ...

Python / 자료형 / 리스트(list)

Python / 자료형 / 리스트(list)

리스트(list) 여러 개의 자료를 하나의 변수로 관리할 때 사용합니다. 리스트 만들기 리스트는 대괄호로 만듭니다. >>> jb = 빈 리스트를 만들 수 있습니다. >>> jb = 리스트 출력하기 print() 함수로 출력해봅니다. >>> jb = >>> print(jb) 리스트는 인덱스를 가집니다. 인덱스를 이용해서 특정 위치의 값을 출력할 수 있습니다. >>> print(jb) four >>> print(jb) 5 범위를 출력할 수 있습니다. >>> print(jb) >>> ...

Python / Database / 연결하는 방법

Python / Database / 연결하는 방법

Python으로 Database에 연결하고 데이터를 조회해 봅니다. Microsoft SQL Server 패키지 설치하기 pymssql를 설치합니다. pip install pymssql 연결하고 데이터 조회하기 pymssql를 import합니다. import pymssql 연결 설정을 합니다. conn = pymssql.connect( server = 'server-ip', port = port-number, user = 'user-name', password = 'pasword', database = 'database-name' ) cursor를 ...

Python / dir() / 객체의 메소드 등을 반환하는 함수

Python / dir() / 객체의 메소드 등을 반환하는 함수

예제 1 a = "Hello" print( dir( a ) ) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', ...

Python / 반복문 / while

Python / 반복문 / while

while while은 주어진 조건이 참일 동안 작업을 반복하게 하는 구문입니다. 문법 while condition: statement condition : 작업을 하기 위한 조건입니다. 참일 동안 반복 작업을 합니다. statement : 반복할 작업입니다. 예제 i가 10보다 작으면 i을 출력합니다. 작업할 때마다 i는 1씩 커지고, i가 10이 되면 while문을 빠져나옵니다. i = 1 while i < 10: print(i, ...

Python / 설치 / 윈도우에 설치하기

Python / 설치 / 윈도우에 설치하기

Windows를 OS로 하는 컴퓨터에 Python을 설치하는 방법이다. 다운로드 및 설치 Python 다운로드 페이지에서 윈도우용 Python을 다운로드 한다. 다운로드한 파일을 실행한다. 기본 설정 그대로 설치해도 되고, 변경을 해도 된다. 는 체크하는 게 좋다. 여러 계정에서 사용할 것이라면 을 클릭하고... 를 클릭한 후... 에 체크하고 설치한다. 설치를 완료하면 를 클릭한다. 테스트하기 IDLE을 실행한다. 다음과 같은 창에서... print( "Hello ...

Python / float() / 자료형을 실수로 변환하는 함수

Python / float() / 자료형을 실수로 변환하는 함수

float()는 데이터 타입을 실수로 변경하는 함수이다. 정수를 실수로 변환한다. 정수일 때는 소숫점 아래가 없지만, 실수일 때는 있다. >>> a = 1 >>> type( a ) <class 'int'> >>> print( a ) 1 >>> b = float( a ) >>> type( b ) <class 'float'> >>> print( b ) 1.0 숫자로 이루어진 문자열을 실수로 변경한다. >>> a = '1' >>> type( a ) <class 'str'> >>> print( ...

Python / 객체(Object)와 변수(Variable)

Python / 객체(Object)와 변수(Variable)

객체(Object), 변수(Variable), 변수명(Variable Name) 메모리에 저장된 자료를 객체(object)라고 한다. 객체를 저장한 공간을 변수(Variable), 변수의 이름을 변수명(Variable Name)이라고 한다. 변수에 객체를 넣을 때 등호 '='을 이용한다. 등호 왼쪽에는 변수명, 등호 오른쪽에는 객체를 적는다. 예를 들어 다음은 객체 100을 x라는 이름의 변수에 저장하겠다는 뜻이다. x = 100 변수명은 다음의 규칙을 지켜야 한다. 규칙에 맞지 않으면 에러가 난다. 키워드를 ...

Python / 사용자 정의 함수 만들고 호출하기

Python / 사용자 정의 함수 만들고 호출하기

함수를 정의하고 호출하는 방법을 알아봅니다. 함수 만들기 def function_name( parameter ) : # code function_name : 함수 이름입니다. 변수명을 만드는 규칙과 같은 규칙으로 만듭니다. parameter : 인수입니다. 인수가 여러 개인 경우 쉼표(,)로 구분합니다. 함수 호출하기 function_name( parameter ) 예제 Hello를 출력하는 함수를 정의합니다. def jb_say_hello() : print('Hello') 함수를 호출하면 Hello가 출력됩니다. >>> jb_say_hello() Hello 함수를 정의하는 위치 함수는 ...