Summary
Talking about the management package for python, in recent years there are quite a lot of support tools, but the advantages and disadvantages of those tools, if not learn through it will certainly be a bit confusing in Choose when starting a new project. In this article, I will be comparing the tools to help us better understand the benefits and how to use them. I am a bit inclined to Poetry so I might be a bit biased, please understand.
Main content:
- Similarities between Pipenv 、 Poetry 、 Pyflow and how to use it.
Content not mentioned:
- Explanation of the tools: Pyenv 、 Venv 、 Virtualenv
Test environment:
- Ubuntu 18.04
- Python 3.8.0
- Pipenv 2018.11.26
- Poetry 1.0.0
- Pyflow 0.2.1
Especially, Poetry and Pyflow are in development, so there may be wrong commands about these two tools. As of 2019/12/15, Star statistics on the github are as follows, only the Poetry 1.0.0 tool was released 7 days ago
Introduce
Pipenv
This tool is used to manage packages with file requirements.txt
(that means managing the libraries listed in this file), for example Node.js has npm, yarn, Ruby has gems, and also can handle the reference of that library (ie, always download dependent libraries to run the main library).
This tool uses file management Pipfile
and file Pipfile.lock
to manage these links. For example, the pandas
library uses numpy
as a mandatory link library, so when installing or deleting pandas
, the numpy library will also be installed or removed.
Pipfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [[source]] name = "pypi" url = "https://pypi.org/simple" verify_ssl = true [dev-packages] black = "*" [packages] numpy = "*" [requires] python_version = "3.8" [pipenv] allow_prereleases = true |
Poetry
While Pipenv is a popular tool, at PEP 518 , pyproject.com introduced Poetry as the official tool used to manage its package.
Pipenv can only be managed on requirements.txt
or alt-requirements.txt
, but for Poetry it can be managed on more channels such as setup.py
, setup.cfg
, MANIFEST.in
, …, in addition It is also possible to setup linter
or formatter
on the same file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [tool.poetry] name = "sample-ploject" version = "1.0.0" description = "" authors = ["Your Name < <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="a8d1c7dde8cdd0c9c5d8c4cd86cbc7c5">[email protected]</a> >"] license = "MIT" [tool.poetry.dependencies] python = "^3.8" numpy = "^1.17.4" [tool.poetry.dev-dependencies] black = {version = "^19.10b0", allow-prereleases = true} [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" |
Pyflow
Pyflow is probably the latest tool, written in Rust, in addition to PEP 518 introduced by Poetey, which was also exported in PEP 582. Pyflow can handle and switch multiple versions of python in the same virtual environment. Unlike Pipenv / Poetry, which only handles a virtual environment of a Python version with Pyenv + venv, Pyflow can manage multiple versions of Python itself and create a virtual environment with any version.
This doesn’t make much sense right now, but it might be useful if there’s a major update to Python in the future. The advantage is that this tool is written in Rust and seems to be beneficial in speed, etc., but the difficult point is that the Rust development community is a bit weak so if there is an error it will take a long time to resolve.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [tool.pyflow] name = "sample-project" py_version = "3.8" version = "1.0.0" authors = ["Your Name < <a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="abd2c4deebced3cac6dbc7ce85c8c4c6">[email protected]</a> >"] [tool.pyflow.scripts] [tool.pyflow.dependencies] numpy = "^1.17.4" [tool.pyflow.dev-dependencies] black = "^19.10.0b0" |
Using
How to install it can be found in the links below.
As for Pyflow, you can basically use Pip to install, but currently Pyflow is discouraging the use of Pip, because it doesn’t seem to like Mac so it is better to install with Rust.
For all the most basic commands, you can refer to the table listed below.
Action | Pip | Pipenv | Poetry | Pyflow |
---|---|---|---|---|
Create project | – | – | poetry new sample | pyflow new sample |
Init project | – | pipenv –python 3.8 | poetry init | pyflow init |
Add package | pip install numpy | pipenv install numpy | poetry add numpy | pyflow install numpy |
Remove package | pip uninstall numpy | pipenv uninstall numpy | poetry remove numpy | pyflow uninstall numpy |
Install depedency | pip install -r requirements.txt | pipenv sync | poetry install | pyflow sync |
Run virtual environment | – | pipenv run python main.py | poetry run python main.py | pyflow main.py |
Build package | python setup.py bdist_whee | – | poetry build | pyflow package |
Upload package (PyPI) | twine upload –repository pypi dist / * | – | poetry publish | pyflow publish |
Looking at the table above, you can see that in Pyflow and Pipenv the commands seem similar, while in the build package, Poetry and Pyflow have the commands that look the brightest.
The structure of the directory after installing a library is as follows (instal numpy)
pipenv-tree
1 2 3 4 5 | ./ ├── .venv/ ├── Pipfile └── Pipfile.lock |
poetry-tree
1 2 3 4 5 6 7 8 | ./ ├── .venv/ ├── poetry.lock ├── pyproject.toml ├── README.rst ├── sample/ └── tests/ |
pyflow-tree
1 2 3 4 5 6 7 8 9 10 | ./ ├── .git/ ├── .gitignore ├── __pypackages__/ ├── LICENSE ├── pyflow.lock ├── pyproject.toml ├── README.md └── sample/ |