Python 연습장
파이썬 패키지 개념과 pip 간단 명령어 모음 본문
내가 그동안 코딩하면서 헷갈렸던 개념과 자주 까먹어서 맨날 구글링해서 입력하는 명령어들을 모아놓았다.
1. 모듈과 패키지의 개념
def func():으로 시작하는 함수, 그리고 class classname:으로 시작하는 class, 이것들을 열심히 적어서 하나의. py 파일로 만들면 그게 모듈이 되고, 이 모듈들을 모아 놓은 게 package이다. package 보다 더 큰 개념(즉, package 들을 모아놓은)이 library인데 package 랑 같이 혼용해서 써도 무방하다. (pandas library = pandas package)
정리하면 이렇게 된다.
[ library >= package > module > class > func ]
예를 들어 sklearn library 안에 preprocessing package 가 있고 그 안에 StandardScaler 라는 모듈이 있다.
우리는 이걸 이런 형태로 import 한다.
from sklearn.preprocessing import StandardScaler
2. 패키지 설치하는 법
다들 아는 방법이겠지만 온라인 환경이라면 terminal / command 창에 pip install packagename 으로 설치하면 된다.
pip install [packagename]
pip install xgboost
만약 offline 환경에서 설치해야 하는 상황이라면 cd foldername1 cd foldername2 로 package setup.py 파일이 설치되어있는 경로로 들어가서 python3 setup.py install 이라고 입력해주면 설치된다.
package setup.py 파일 다운은 pypi.org 에서 검색 > Download files 에서 해주면 된다.
3. 패키지 지우는 방법
잘못설치한 경우에는 uninstall 할 수 있다.
pip uninstall [packagename]
pip uninstall xgboost
proceed [y/n] 이 떴을 때 y 입력해주면 삭제된다.
4. 패키지 업그레이드하는 방법
pip install --upgrade [packagename]
pip install --upgrade pandas
5. 패키지 다운그레이드 하는 방법
package 이름 옆에 == version을 입력해주면 상위 버전은 삭제되고 지정한 버전으로 새로 깔린다.
pip install [packagename]==[version_number]
pip install pandas==1.3.1
6. 설치된 패키지 목록을 확인하는 방법
pip list
Package Version
---------------------- -------------------
appnope 0.1.2
backcall 0.2.0
brotlipy 0.7.0
catboost 1.0.3
category-encoders 2.3.0
위와 같은 식으로 설치된 모든 Package 들의 리스트와 버전이 나와서 체크하기 용이하다.
7. python 설치 버전 확인 방법
python3 --version
터미널 창에 위와 같이 입력해주면 Python 3.9.5라고 Python 설치 버전을 뱉어낸다.
8. 그 외 pip 의 명령어 기능 확인 방법
pip help
위와 같이 터미널/cmd 창에 입력 시 아래와 같은 명령어, 옵션 모음이 나온다.
근데 사실 저 위에 하나씩 기술한 거 외에는 잘 써본 적이 없다.
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. cache Inspect and manage pip's wheel cache. index Inspect information available from package indexes. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. debug Show information useful for debugging. help Show help for commands. |
9. pip 자체를 업그레이드 하는 방법
pip install --upgrade pip
#혹은
pip install --user --upgrade pip
가끔 Package install 하다보면 pip warning 뜨면서 consider upgrade 하라고 하는데 이 때는 위와 같이 --upgrade package 대신 pip 라고 입력해주면 된다.
'코딩' 카테고리의 다른 글
분류(classification)의 평가지표와 confusion matrix (0) | 2022.01.21 |
---|---|
category_encoders (1) (0) | 2022.01.20 |
categorical data encoding 방법 (0) | 2022.01.14 |
Python Visualization(5) - seaborn (0) | 2022.01.10 |
pipeline (0) | 2022.01.09 |