카테고리 없음
나도 pip install 어쩌구 할래.. python pypi 업로드
SciomageLAB
2024. 10. 18. 00:08
반응형
파이썬 패키지 생성을 위해서 아래 파일 구조를 따라야 한다. ```
├── README.md
├── res
│ ├── 01.gif
│ ├── 02.gif
│ └── 03.gif
├── setup.py
└── telegram_notification
├── README.md
├── __init__.py
├── __main__.py
├── config.ini
├── install.sh
├── noti
├── requirements.txt
└── telegram_notification.py
README.md는 github이나 pypi에 표시하기 위한 마크다운 파일이고 res는 README에서 보여줄 참고용 이미지 파일이다.
아래 ``setup.py이 특별히 중요하다. 공식 문서를 보면 자세하고 엄격한 설명이 되어 있는데 내용이 많기 때문에 원하는 걸 찾기 힘들 수 있다.
import setuptools
with open(README.md, r) as fh:
long_description = fh.read()
setuptools.setup(
name=telegram_notification, # Replace with your own username
version=0.1.3,
author=dankernel,
author_email=dkdkernel@gmail.com,
description=A small example package,
long_description=long_description,
long_description_content_type=text/markdown,
url=https://github.com/dankernel/telegram_notification,
packages=setuptools.find_packages(),
install_requires = ['python-telegram-bot'],
scripts=['telegram_notification/noti', 'telegram_notification/config.ini'],
package_data = {'': ['telegram_notification/config.ini']},
include_package_data=True,
classifiers=[
Programming Language :: Python :: 3,
License :: OSI Approved :: MIT License,
Operating System :: OS Independent,
],
python_requires='>=3.6',
)
특히 이 패키지는 import ....
해서 쓰는 것 뿐만 아니라 터미널에서 그냥 $ noti
라고 하면 패키지의 main이 실행되는.. 일종의 유틸리티이기 때문에 /usr/bin 아래에 복사하고 싶었는데, scripts=
에 파일 리스트를 쓰면 된다. 실행에 필요한 ini 파일을 함께 써 주면 된다.
package_data
도 python 파일 이외에 ini 파일을 함께 지정하기 위해서 사용했다.
빌드, 설치, pypi 업로드는 아래와 같다.
sudo python3 setup.py bdist_wheel
sudo python3 setup.py install
sudo python3 -m twine upload dist/*.whl
잘 업로드 되어서 https://pypi.org/project/telegram-notification/ 에 등록이 되었고, pip install telegram-notification
으로 설치 할 수 있다.
```
반응형