-
Notifications
You must be signed in to change notification settings - Fork 10
Package Development Process
- You've gone through Create A Package
- Install pyenv
You should avoid running Python with python3 and pip3, it's confusing and inconsistent. You should always use a clean python and pip, and let pyenv do the heavy-lifting for choosing the right Python version.
pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
pyenv is great for checking backward compatibility, for example, I have Python 3.8.2 installed and I'd like to check if my Python package runs properly on Python 3.6.7, which is a classic use-case.
- Install the relevant Python version -
pyenv install 3.7.7 - Run
export PYENV_VERSION=3.7.7
-
For a day to day use
- Install relevant version -
pyenv install 3.8.2 - Add
export PYENV_VERSION=3.8.2to your terminal'srcor_profile($HOME/.bashrc,$HOME/.bash_profile,$HOME/.zshrc)
- Install relevant version -
(python-project) $ export PYENV_VERSION=
(python-project) $ pyenv versions
* system (set by /Users/meirgabay/.pyenv/version) # default OS Python
3.7.7
3.8.2
(python-project) $ python --version
Python 2.7.16
# Switching to a different version
(python-project) $ export PYENV_VERSION=3.7.7
(python-project) $ python --version
Python 3.7.7
# Day to day use
# Add export PYENV_VERSION=3.8.2 to your ~/.bash_profile
(python-project) $ source ~/.bash_profile
(python-project) $ python --version
Python 3.8.2If this is the first time you hear this term, then I suggest you go read about the venv package.
Using virtual environments assists with isolating the package's requirements (packages) from the packages which are installed on your machine.
(python-project) $ python -m venv ENV
(python-project) $ source ./ENV/bin/activate
(ENV) (python-project) $ pip install .
(ENV) (python-project) $ pip freeze > requirements.txt # generate a list of required packages with version constraints
(ENV) (python-project) $ deactivate
(python-project) $ # we're out of the virtual environmentIt's possible to install the package from Source code, though each time that your code changes, you'll need to re-install the package to test the newly added features.
$ pip install .
Processing /Users/meirgabay/python-project
Building wheels for collected packages: unfor19-appy
...
Successfully installed unfor19-appy-0.0.1
Adding the --editable flag enables checking the latest changes of your code, without re-installing the package.
$ pip install --editable .
You don't need to do pip install . after each time you change the source code. Simply run pip install --editable . once, and start developing your Python package!
-
Run
appyas a CLI$ appy Insert your name: willy Hello willy -
Run
appyas a Python module$ python -m appy My Path: .pyenv/versions/3.8.2/Python.framework/Versions/3.8/lib/python3.8/site-packages/unfor19_appy-0.0.1-py3.8.egg/appy/__main__.py Insert your name: willy Hello willy
-
Import
appyas a package$ python ... >>> from appy.utils import message >>> message.greet("willy") Hello willy
$ pip uninstall -y unfor19-appy
Found existing installation: unfor19-appy 0.0.1
Uninstalling unfor19-appy-0.0.1:
Successfully uninstalled unfor19-appy-0.0.1
- Home
- Python
- Docker
- Intro
- Build A Docker Image
- Multistage Build
- CI/CD
- Intro
- GitHub Actions