Skip to main content

Python starter package, a template for creating your own python packages.

Project description

Python Starter Package

This is a basic python starter package to be used as a template for creating your own python packages. See "PythonStarterPackage Setup Guide.md" in doc/ for a detailed explanation of the package resources.

Prerequisites

For Windows, it is recommended to run this app on a Linux emulation layer such as the Git Bash terminal. See the "Instructions for Git Bash" section for details. In addition to Git Bash, make sure you also have Python3 and Pip3 as described below.

For Mac and Linux, this app should work out of the box on the Linux or Mac terminal, but make sure you also have Python3 and Pip3 as described below.

Requirements:

  • Python3 (version 3.8 or greater) - Install Python3 here: [https://www.python.org/downloads/]. Check version with: python3 --version.
  • Pip3 (version 20.2.1 or greater) - Make sure to install python3-pip in order to use pip install. Check version with: pip3 --version.

Installation

There are a couple of options to install this app:

  • Pip Install - This app is hosted on PyPi and can be installed with the following command:
pip3 install PythonStarterPackage
  • Local Install - Alternatively, you can download or git clone the Github repo and install it locally with the following:
git clone https://github.com/MysticTechnology/PythonStarterPackage.git
cd PythonStarterPackage
pip3 install -e .

To uninstall this app:

pip3 uninstall PythonStarterPackage
  • If you used the local install option, you will also want to delete the .egg-info file located in the src/ directory of the package. This gets created automatically with pip3 install -e ..

Usage

After installation, you have a couple ways to run this app.

  • Run this app from the terminal with this command:
pythonstarterpackage
  • Run this app with the python command python3 -m:
python3 -m pythonstarterpackage
  • You can also import the package resources and run them in your own project:
from pythonstarterpackage import *
starter = StarterPkg()
starter.run()

Documentation

The purpose of this project is to show you how to create a standard python package from scratch. This project is inspired by this excellent getmyip package by @iamtennislover: [https://github.com/iamtennislover/getmyip] and this great guide on deploying python packages by @sigma-coding: [https://github.com/areed1192/sigma-coding].

Setup

See "PythonStarterPackage Setup Guide.md" in doc/ for a detailed walkthrough of what each of the package resources do. Once you have an understanding of this package, you can clone this package to your local directory and proceed to testing and deployment.

Testing

In the directory containing the setup.py file, you can test the package by installing it in pip3 editable mode. This will allow you make changes to it and test it without having to push the changes each time.

  1. Use pip3 to install the package in editable mode:
pip3 install -e .
  1. Run the package by calling the package directly:
pythonstarterpackage

Or use python3 -m:

python3 -m pythonstarterpackage
  1. Testing the import. Run the test_main.py file:
python3 ./test/test_main.py
  1. Once finished, delete the pythonstarterpackage.egg-info file and uninstall the package with:
pip3 uninstall PythonStarterPackage

Note: It is recommended that you use a virtual environment when testing your package.

  1. To create a virtual environment:
virtualenv venv
  1. Activate the environment use: . venv/bin/activate. On Windows it may be: . venv/Script/activate.

Dependency Mapping

Next, make sure to check the package dependencies and update the setup.cfg file as needed. To do this:

  1. Create (or overwrite) the requirements.txt document with pipreqs. This is an extremely useful tool because it automatically finds all of the relevant versions of dependencies your package relies on and puts them into the requirements.txt file. If you don't have pipreqs, install it with pip install pipreqs.
pipreqs --force --encoding utf-8
  1. Once the requirements.txt is updated, check to see if there is any additional dependencies that need to be added or updated in setup.cfg under the install_requires =. If so, add or update it.

Deployment

Once the package is ready, we can work on deploying the package.

  1. Upgrade setuptools, wheel, and twine (twine will be used in the next part).
pip3 install --upgrade setuptools wheel twine
  1. Build the package with setup.py.
python3 setup.py sdist bdist_wheel
  1. Check the contents of the .whl and .tar.gz distributions. The key things to look for are: (1) all of your package subdirectories like utils are added to both distributions, (2) your config and package data are included in both distributions.
unzip -l dist/*.whl && tar --list -f dist/*.tar.gz
  1. Test a local install of the package and run it to make sure it is working.
pip3 install .
pythonstarterpackage
  1. After testing that it is working, uninstall the package from pip3.
pip3 uninstall pythonstarterpackage

If there are any issues in the above you can always uninstall the package and delete the distributions then proceed to troubleshoot the issue. Once complete start over from the beginning. The commands below allows you to delete the distributions.

rm -rf build dist src/*.egg-info

BE CAREFUL not to miss copy the above command, as if you delete something you didn't intend you will not be able to retrieve.

Upload to PyPi

In order to upload to PyPi make sure to setup your PyPi account first. See "PyPi Setup Guide.md" in doc/ for more details. You will also need to have twine installed and upgraded. Once you have all of this setup do the following:

  1. Upload using twine.
twine upload dist/*
  1. Install your package with pip.
pip3 install pythonstarterpackage

Note: If you get a "Requirements already satisfied..." for pythonstarterpackage when trying to install, it may be because pip still thinks you have the package already installed from the testing earlier. To cleanly break that connection, simply delete the ./src/PythonStarterPackage.egg-info. Then try uninstalling and reinstalling again.

  1. Finally, run the app with: pythonstarterpackage.
  2. Uninstall with: pip3 uninstall pythonstarterpackage.

Troubleshooting

This section goes over some of the common issues found and how to resolve them.

"Command Not Found" Error When Running the App

On Linux, if you are getting a command not found error when trying to run the app, you may need to add ~/.local/bin/ to PATH. See this thread for details: [https://stackoverflow.com/a/34947489]. To add ~/.local/bin/ to PATH do the following:

  1. Add export PATH=~/.local/bin:$PATH to ~/.bash_profile.
echo export PATH=~/.local/bin:$PATH > ~/.bash_profile
  1. Execute command.
source ~/.bash_profile

"ImportError: No module named 'tkinter'

Your python version is probably missing tkinter which typically comes default. See this post for details [https://stackoverflow.com/a/25905642]. Install it with the following:

sudo apt-get install python3-tk

For Mac, use this:

brew install python-tk

Instructions for Git Bash

For Windows, it is recommended to run this app on a linux emulation layer like the Git Bash terminal. Here are the instructions for installing and setting up Git Bash:

  1. Go to https://git-scm.com/downloads and click download.
Version >= 2.34.1
  1. During the installation setup, make sure to include OpenSSH. Recommenced setting should be fine:
Use bundled OpenSSH - This uses ssh.exe that comes with Git.
  1. Leave the other settings as default, click through, and install.
  2. Open bash.exe and install Python3 https://www.python.org/downloads/
  3. Proceed to the "Installation" section to install this app.

IMPORTANT: For Windows, use the bash.exe terminal rather git-bash.exe. There is a known issue with git-bash.exe messing up Python os commands in import os. See this thread for details: [https://stackoverflow.com/a/33623136].

  • You can find bash.exe Git folder in the bin/ directory. For example: If git-bash.exe is here C:\Program Files\Git\git-bash.exe then you should find bash.exe here C:\Program Files\Git\bin\bash.exe.

Support and Contributions

Our software is open source and free for public use. If you found any of these repos useful and would like to support this project financially, feel free to donate to our bitcoin address.

Bitcoin Address 1: 1GZQY6hMwszqxCmbC6uGxkyD5HKPhK1Pmf

alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PythonStarterPackage-0.4.4.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

PythonStarterPackage-0.4.4-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file PythonStarterPackage-0.4.4.tar.gz.

File metadata

  • Download URL: PythonStarterPackage-0.4.4.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.0

File hashes

Hashes for PythonStarterPackage-0.4.4.tar.gz
Algorithm Hash digest
SHA256 80b1412760144a02c4261ee7b9065618e936e6d9eda9658f68b97a181a228512
MD5 277aad978287ef47f2bb8ea948e28330
BLAKE2b-256 b87e3432341d6ba50a6983992e5625a8e50d2e84d6faab3bce781e5b3e38c143

See more details on using hashes here.

File details

Details for the file PythonStarterPackage-0.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for PythonStarterPackage-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b6b4a2e517330cb7f446d02be7955b0fb08d40773e63c00502fbe1634fe63183
MD5 bb8b356beebda3b827d3ffdff365d3e1
BLAKE2b-256 2b8563a33b4a63b2da15d5d6c8d2c389ae686c65134ed1bbdeb269268efc0c9a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page