Why Delphi programmer needs Python at all? The main reason is: Python ecosystem is much bigger and much more active than Delphi ecosystem; there are many useful and actively developing projects in Python, much more than you can find in Delphi. Currently I am dabbling in a nice MkDocs documentation generator and planning to use it for documenting my project.
The first thing you need to understand about Python is project isolation. In Delphi you can add units, packages, etc to a project and it does not affect other projects; the Delphi projects are well isolated. If you simply install Python and start developing projects, you quickly discover that there is no project isolation at all; if you add python package for one project, the package becomes available for all projects. It is quite stunning when you encounter it for the first time, but there is a solution: you need a separate Python installation for each project. These separate installations are called environments. The idea is: you have one global Python installation with the sole purpose of creating environments; you never use the global installation for developing projects. When you start a new project you create a new environment, and when later on you add packages to the environment it does not affect global installation or other environments.
There are several ways to create environments, the way I use is Conda package manager.
I am using Python on Linux Mint, and Linux Mint already has Python installed (on Windows you probably need to install Python first). But this Python belongs to the system; the system installed it for its own purposes, and trying to modify the system Python is bad idea. Good news are: Python is Conda installation requirement, and you have it.
Go to Miniconda download page and download Miniconda for your system. There are two installer versions, based on Python 2 and Python 3 – use the one based on Python 3; it does not matter much; by default Python 3 version creates Python 3 environments. Don’t install Anaconda – if you want to play with Anaconda install it later into environment.
Open Terminal window, go to the download folder and run the downloaded installer; accept the default settings and answer “yes” to the installer questions. After the installation is completed close the Terminal window and open it again. Now you have Python installed in your home folder; to check it run which python command:
serg@TravelMate ~ $ which python /home/serg/miniconda3/bin/python
This is global Python installation that will be used to create environments.
To play with MkDocs I’ve created environment named mkdocs:
conda create -n mkdocs pip
pip is Python package manager that will be included in the new environment. Conda documentation may say that you need not pip because you can install everything using Conda itself; I believe this is too good to be true, and prefer to have pip in any environment, and it is better to install pip right in the environment create command.
Now we need to activate the newly created environment; after the activation check that we have different python installed in the environment:
serg@TravelMate ~ $ source activate mkdocs (mkdocs) serg@TravelMate ~ $ which python /home/serg/miniconda3/envs/mkdocs/bin/python
The next step is to upgrade pip in the environment:
pip install --upgrade pip
and finally install MkDocs package into the environment:
pip install mkdocs
Check that mkdocs is installed:
(mkdocs) serg@TravelMate ~ $ mkdocs --version mkdocs, version 1.0.2 from /home/serg/miniconda3/envs/mkdocs/lib/python3.7/site-packages/mkdocs (Python 3.7)
If you are not going to do more for now, deactivate the environment
(mkdocs) serg@TravelMate ~ $ source deactivate serg@TravelMate ~ $
or just close the Terminal window.