knowledge_base:programming:python:python_pkg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

knowledge_base:programming:python:python_pkg [2024/12/26 23:25] – created Normal Userknowledge_base:programming:python:python_pkg [2024/12/26 23:31] (current) – [Step 5: Creating setup.py] Normal User
Line 89: Line 89:
  
 </code> </code>
 +
 +===== Step 6: Writing the README and LICENSE =====
 +
 +
 +Your ''README.md'' should provide an overview of your package:
 +
 +<code>
 +# My Package
 +
 +A simple example package.
 +
 +## Installation
 +
 +```bash
 +pip install package_publishing
 +</code>
 +
 +===== Step 7: Building and Distributing Your Package =====
 +
 +
 +To build your package, run:
 +<code>
 +pip install wheel
 +python setup.py sdist bdist_wheel
 +</code>
 +This creates a ''dist/'' directory with the distribution files.
 +
 +===== 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:
 +
 +<code>
 +git init
 +git add .
 +git commit -m "Initial commit"
 +git remote add origin https://github.com/yourusername/package_publishing.git
 +git push -u origin main
 +</code>
 +Replace ''yourusername'' with your GitHub username and ''package_publishing'' with your repository name.
 +
 +===== 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.
 +  *     Select “Developer settings” > “Personal access tokens”.
 +  *     Select ‘Tokens (classic)”
 +  *     Click “Generate new token” > “Generate new token (classic)”
 +  *     Select the scopes you need (e.g., repo), and give the token a Note
 +  *     Click “Generate token” and copy the token.
 +
 +You can now use this token to install your package:
 +<code>
 +pip install git+https://<your-token>@github.com/yourusername/package_publishing.git
 +</code>
 +Replace ''<your-token>'' with your PAT, ''yourusername'' with your GitHub username, and ''package_publishing'' with your repository name.
  • Last modified: 2024/12/26 23:25
  • by Normal User