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

Related Posts

Python / print() / 출력하는 함수

Python / print() / 출력하는 함수

Python의 print() 함수 사용법을 정리합니다. 큰 따옴표를 이용하여 Hello를 출력합니다. print("Hello") Hello 작은 따옴표를 이용하여 Hello를 출력합니다. print('Hello') Hello 작은 따옴표를 출력하려면 큰 따옴표로 감쌉니다. print("'Hello'") 'Hello' 큰 따옴표를 출력하려면 작은 따옴표로 감쌉니다. print('"Hello"') "Hello" 쉼표로 연결할 수 있습니다. 공백이 생깁니다. print("Hello","JB") Hello JB print() 함수를 연달아 사용하면 다른 줄에 출력됩니다. print("Hello") print("JB") Hello JB 줄바꿈 없이 출력하려면 end를 사용합니다. print("Hello",end=" ") print("JB") Hello JB sep를 이용하여 출력 값 사이에 특정 문자를 넣을 수 있습니다. print("A","B","C","D",sep=" ...

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

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

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

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 / PyCharm 설치하는 방법

Python / PyCharm 설치하는 방법

PyCharm는 Python 개발 도구 중의 하나입니다. JetBrains에서 만든 것으로, 모든 기능이 있는 프로페셔널 에디션과, 기능의 제한이 있지만 무료로 사용할 수 있는 커뮤니티 에디션이 있습니다. 아래는 OS가 Windows인 컴퓨터에 PyCharm 커뮤니티 에디션을 다운로드하고 설치하는 방법입니다. 참고로, Python이 설치되어 있지 않아도 괜찮습니다. PyCharm에서 프로젝트를 만들 때 자동으로 Python을 다운로드 합니다. PyCharm 페이지에서 를 클릭합니다. Community ...

Python / input() / 사용자가 입력한 값을 변수에 저장하는 함수

Python / input() / 사용자가 입력한 값을 변수에 저장하는 함수

input() 함수로 사용자가 어떤 값을 입력하게 하고, 그 값을 변수에 저장할 수 있습니다. 문법 예를 들어 다음을 입력하고 엔터를 누르면 사용자가 값을 입력하기를 기다립니다. >>> x = input() 값을 입력하고 엔터를 누르면 그 값이 변수 x에 저장됩니다. >>> x = input() hello >>> x 'hello' 입력할 값에 대한 안내를 출력하고 싶다면 다음과 같이 합니다. >>> x = input('some text') 작은 따옴표 ...

Python / Visual Studio Code 개발 환경 만들기

Python / Visual Studio Code 개발 환경 만들기

파이썬 개발을 위한 도구는 여러 가지가 있습니다. Visual Studio Code도 그 중 하나입니다. VS Code에 Python 확장 기능을 설치하고, Hello World를 출력해보겠습니다. 확장 기능 설치 Visual Studio Code를 설치하고 실행합니다. 사각형 모양의 확장 기능 아이콘을 클릭합니다. python으로 검색한 후, 다운로드 수가 가장 많은 Microsoft가 만든 Python을 설치합니다. Reload Required를 클릭합니다.(VS Code 버전에 따라 나오지 않을 ...

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 / 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 / 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 / PIP(Python Package Index) 사용법

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를 ...