Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PyThemis installation instructions #317

Merged
merged 12 commits into from
Nov 30, 2023
145 changes: 144 additions & 1 deletion content/themis/languages/python/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,151 @@ Once PyThemis is installed, you can [try out code examples](../examples/).
If the stable package version does not suit your needs,
you can manually build and install the latest version of Themis from source code.

1. [Build and install Themis Core library](/themis/installation/installation-from-sources/)
into your system.

2. Install Python dependencies

Depending on how you want to install PyThemis, there are different requirements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's list the available approaches. One into the virtualenv and one system-wide installed as system package. Because further we describe steps how install dependencies, but not obvious for what. And why the user needs .whl. Usually developers installs packages with commands like pip install or python setup.py and they don't care what the files are generated. They interested in the package installed into their local or system environment. So we should clarify that we support 2 approaches. Local installation into venv and you need next dependencies, or installation into the system using system package manager and you need next dependencies.


To create a `.whl` package for installation inside virtualenv, you'll need `setuptools` and `wheel`

* Install globally

For Debian, Ubuntu:

```bash
sudo apt install python3-setuptools python3-wheel
```

<!--
For CentOS, RHEL:

```bash
sudo yum install python3-setuptools python3-wheel
```
-->

* Or install into virtualenv
vixentael marked this conversation as resolved.
Show resolved Hide resolved

```bash
# activate virtualenv if not done yet
pip install setuptools wheel
```

---

To create a system package (i.e. `.deb` one for Debian) you will need `pip` and `fpm`

* Install globally

For Debian, Ubuntu:

```bash
sudo apt install python3-pip lsb-release ruby
sudo gem install fpm
```

<!--
For CentOS, RHEL:

```bash
sudo yum install python3-pip ruby
sudo gem install fpm
```

On RHEL you also need to have working `pip` command. If it's not, and you only got `pip3`,
create a symlink like this: `sudo ln -s $(which pip3) /usr/bin/pip`.
-->

3. Create a PyThemis package

* Create a "wheel" for virtualenv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to explicitly note for which way this case. For example To install locally: Create a "wheel".... Or mentions at start that we will describe 2 ways, first for local installation and second one for system. And then mention it like Way 1. ...., Way 2. ....

Because when I read step 3, I didn't understand why we need .whl for system package below and went to the makefile in the themis...


{{< hint info >}}
If you installed dependencies globally, virtualenv should not be activated during wheel
generation since needed packages won't be visible in an isolated environment.
{{< /hint >}}

```bash
make pythemis_make_wheel
```

Result package filename will be printed at the end, like this:
```
Result: src/wrappers/themis/python/dist/pythemis-0.14.0-py2.py3-none-any.whl
```

* Create package for your distro

For Debian, Ubuntu:

```bash
make pythemis_deb
```

<!--
For CentOS, RHEL:

```bash
make pythemis_rpm
```

The result will be located at `build/rpm/python3-pythemis_..._all.rpm`
or `build/rpm/python3-pythemis_..._all.rpm` respectively.
-->

4. Install PyThemis

* Install a wheel into virtualenv

```bash
# activate virtualenv if not done yet
make pythemis_install_wheel
```

Or manually run `pip install path/to/pythemis-...-none-any.whl` (the package file previously created).
If the virtual environment already contained PyThemis of the same version,
add `--force-reinstall` option to rewrite the previous package.

* Install system package

For Debian, Ubuntu:

```bash
make pythemis_install_deb
```

For manual installation, there are two ways:
1. `sudo apt install ./path/to/package.deb` (the `./` is important here!)
2. `sudo dpkg -i path/to/package.deb`

<!--
For CentOS, RHEL:

```bash
make pythemis_install_rpm
```
-->

## Building latest version from source (deprecated)
iamnotacake marked this conversation as resolved.
Show resolved Hide resolved

{{< hint warning >}}
[PEP 668](https://peps.python.org/pep-0668/) changed the way Python packages are managed.
It is now recommended to use `pip install` to only install packages into isolated virtual environments
while installing things system-wide should be done using OS package manager (like `apt` or `rpm`).
vixentael marked this conversation as resolved.
Show resolved Hide resolved
This means running `sudo make pythemis_install` is no longer recommended as it copies files
into system-managed Python directory (like `/usr/lib/python3.X/site-packages`) that is no longer maintained by `pip`.
Consider building a `.whl` and installing it into your venv instead.
{{< /hint >}}

1. [Build and install Themis Core library](/themis/installation/installation-from-sources/)
into your system.

2. Install PyThemis package from the source code:

```bash
make pythemis_install
sudo make pythemis_install
```

The package will be installed globally into the system.
Expand All @@ -91,3 +229,8 @@ you can manually build and install the latest version of Themis from source code
```bash
make prepare_tests_all test_python
```

To remove PyThemis after using `pythemis_install`, run
```bash
sudo pip uninstall --break-system-packages pythemis
vixentael marked this conversation as resolved.
Show resolved Hide resolved
```