IT
Python 패키지 PyPI에 업로드하기
yeTi
2020. 7. 22. 14:56
안녕하세요. yeTi입니다.
오늘은 Python 모듈을 패키징하여 The Python Package Index (PyPI)에 공유해보려고 합니다.
Packaging Python Projects를 참고하여 진행했습니다.
예제 프로젝트 생성
practice-python-packaging - GitHub과 같이 샘플 프로젝트를 생성합니다.
Generating distribution archives
패키징에 사용할 setuptools
과 wheel
을 업그레이드합니다.
> python3 -m pip install --user --upgrade setuptools wheel
distribution archives를 생성합니다.
> python3 setup.py sdist bdist_wheel
...
creating ho.egg-info
...
creating dist
...
creating build
...
Uploading the distribution archives
TestPyPI의 계정을 생성 후 API Tocken
을 생성합니다.
배포파일 업로드를 위해 Twine
을 설치합니다.
> python3 -m pip install --user --upgrade twine
TestPyPI에 배포파일을 업로드합니다. 이 때 앞서 생성한 토큰을 입력합니다.
> python3 -m twine upload --repository testpypi dist/*
...
Enter your username: __token__
Enter your password:
...
Installing your newly uploaded package
업로드 후 Test PyPI에서 배포시 정한 이름으로 검색하면 패키지가 검색되는것을 확인할 수 있습니다.
python
환경에서 모듈을 다운받을때는 다음과 같이 pip
를 사용하면 됩니다.
> python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps ho-hello
Release
The Python Package Index (PyPI)에 업로드를 위해서는 --repository
옵션만 제거하면 됩니다.
> python3 -m twine upload dist/*
그러면 The Python Package Index (PyPI) 모듈을 검색할 수 있고 pip install [your-package]
로 모듈을 다운받을 수 있습니다.
활용 예제입니다.