Differences
This shows you the differences between two versions of the page.
knowledge_base:programming:python:python_pkg [2024/12/26 23:25] – created Normal User | knowledge_base:programming:python:python_pkg [2024/12/26 23:31] (current) – [Step 5: Creating setup.py] Normal User | ||
---|---|---|---|
Line 89: | Line 89: | ||
</ | </ | ||
+ | |||
+ | ===== Step 6: Writing the README and LICENSE ===== | ||
+ | |||
+ | |||
+ | Your '' | ||
+ | |||
+ | < | ||
+ | # My Package | ||
+ | |||
+ | A simple example package. | ||
+ | |||
+ | ## Installation | ||
+ | |||
+ | ```bash | ||
+ | pip install package_publishing | ||
+ | </ | ||
+ | |||
+ | ===== Step 7: Building and Distributing Your Package ===== | ||
+ | |||
+ | |||
+ | To build your package, run: | ||
+ | < | ||
+ | pip install wheel | ||
+ | python setup.py sdist bdist_wheel | ||
+ | </ | ||
+ | This creates a '' | ||
+ | |||
+ | ===== Step 8. Initialize Git and Push to GitHub ===== | ||
+ | |||
+ | |||
+ | In your project directory, run the following commands to initialize a Git repository, add your files, commit them, and push to GitHub: | ||
+ | |||
+ | < | ||
+ | git init | ||
+ | git add . | ||
+ | git commit -m " | ||
+ | git remote add origin https:// | ||
+ | git push -u origin main | ||
+ | </ | ||
+ | Replace '' | ||
+ | |||
+ | ===== Using Your Package ===== | ||
+ | |||
+ | |||
+ | Now that you’ve published your package, you’ll want to use it. First thing to do if your code sits in a private repository is to create yourself a personal access token. Follow these steps to generate a PAT: | ||
+ | |||
+ | * Go to GitHub Settings. | ||
+ | * | ||
+ | * | ||
+ | * Click “Generate new token” > “Generate new token (classic)” | ||
+ | * | ||
+ | * Click “Generate token” and copy the token. | ||
+ | |||
+ | You can now use this token to install your package: | ||
+ | < | ||
+ | pip install git+https://< | ||
+ | </ | ||
+ | Replace ''< |