이세개발
article thumbnail
Published 2024. 1. 23. 10:53
pip install 등록 (pypi) 카테고리 없음

https://pypi.org/account/register/

 

Create an account

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

pypi.org

가입하기

PyPI에 업로드할 수 있는 간단한 Python 라이브러리를 만드는 과정을 예시 코드와 함께 설명하겠습니다. 예를 들어, 간단한 수학 연산을 수행하는 라이브러리를 만든다고 가정해 보겠습니다.

1. 라이브러리 구조

먼저, 라이브러리의 디렉토리 구조를 설정합니다. 일반적인 구조는 다음과 같습니다:

hankyo/
|-- hankyo/
|   |-- __init__.py
|   `-- math_functions.py
|-- tests/
|   `-- test_math_functions.py
|-- README.md
|-- LICENSE
`-- setup.py

여기서 hankyo는 라이브러리의 이름입니다. 이 이름은 고유해야 하며 PyPI에서 아직 사용되지 않은 이름이어야 합니다.

2. 라이브러리 코드 작성

math_functions.py 파일에 간단한 수학 함수를 작성합니다.

# hankyo/hankyo/math_functions.py

def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

3. __init__.py 설정

__init__.py 파일에서 이 함수들을 import합니다.

# hankyo/hankyo/__init__.py

from .math_functions import add, subtract

4. README 파일 작성

README.md 파일에 라이브러리에 대한 설명을 추가합니다.

# MyLibrary

MyLibrary는 기본적인 수학 연산을 제공하는 Python 라이브러리입니다.

## 설치

pip install mylibrary

## 사용 방법

```python
from mylibrary import add, subtract

print(add(1, 2))  # 3
print(subtract(2, 1))  # 1

6.LICENSE 파일 추가



적절한 라이선스(예: MIT, GPL)를 선택하여 `LICENSE` 파일에 포함시킵니다.

### 7. `setup.py` 작성

`setup.py` 파일을 작성하여 라이브러리의 메타데이터를 정의합니다.

```python
# setup.py

from setuptools import setup, find_packages

setup(
    name="mylibrary",
    version="0.1",
    packages=find_packages(),
    install_requires=[],
    author="Your Name",
    author_email="your.email@example.com",
    description="A simple math library for Python",
    long_description=open('README.md').read(),
    long_description_content_type='text/markdown',
    url="https://github.com/yourusername/mylibrary",
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)

8. 라이브러리 빌드 및 업로드

이제 라이브러리를 PyPI에 업로드할 준비가 되었습니다. 빌드 및 업로드 절차는 다음과 같습니다:

  1. twinesetuptools를 설치합니다: pip install twine setuptools wheel
  2. 라이브러리를 빌드합니다: python setup.py sdist bdist_wheel
  3. 빌드된 라이브러리를 PyPI에 업로드합니다:
    python -m twine upload dist/*​

 

username : __token__
password : ~~~~

이렇게 입력을 해 주셔야 등록이 됩니다.

이 과정을 통해 라이브러리를 PyPI에 업로드할 수 있습니다.

profile

이세개발

@print(name)

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!