2020-10-30 14:08:56 -04:00
---
stage: none
group: unassigned
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-30 14:08:56 -04:00
---
2019-03-16 17:49:59 -04:00
# Python Development Guidelines
2020-02-03 22:08:37 -05:00
GitLab requires Python as a dependency for [reStructuredText ](https://docutils.sourceforge.io/rst.html )
2019-03-16 17:49:59 -04:00
markup rendering.
As of GitLab 11.10, we require Python 3.
## Installation
2019-08-30 01:56:51 -04:00
There are several ways of installing Python on your system. To be able to use the same version we use in production,
2021-01-22 19:08:46 -05:00
we suggest you use [`pyenv` ](https://github.com/pyenv/pyenv ). It works and behaves similarly to its counterpart in the
Ruby world: [`rbenv` ](https://github.com/rbenv/rbenv ).
2019-03-16 17:49:59 -04:00
### macOS
To install `pyenv` on macOS, you can use [Homebrew ](https://brew.sh/ ) with:
2020-01-30 10:09:15 -05:00
```shell
2019-03-16 17:49:59 -04:00
brew install pyenv
```
2022-05-13 14:08:33 -04:00
### Windows
`pyenv` does not officially support Windows and does not work in Windows outside the Windows Subsystem for Linux. If you are a Windows user, you can use `pyenv-win` .
To install `pyenv-win` on Windows, run the following PowerShell command:
```shell
Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; & "./install-pyenv-win.ps1"
```
[Learn more about `pyenv-win` ](https://github.com/pyenv-win/pyenv-win ).
2019-03-16 17:49:59 -04:00
### Linux
To install `pyenv` on Linux, you can run the command below:
2020-01-30 10:09:15 -05:00
```shell
2020-12-09 01:09:41 -05:00
curl "https://pyenv.run" | bash
2019-03-16 17:49:59 -04:00
```
2020-12-11 01:10:17 -05:00
Alternatively, you may find `pyenv` available as a system package via your distribution's package manager.
2019-03-16 17:49:59 -04:00
2021-01-22 19:08:46 -05:00
You can read more about it in [the `pyenv` prerequisites ](https://github.com/pyenv/pyenv-installer#prerequisites ).
2019-03-16 17:49:59 -04:00
### Shell integration
2021-01-22 19:08:46 -05:00
`Pyenv` installation adds required changes to Bash. If you use a different shell,
2019-03-16 17:49:59 -04:00
check for any additional steps required for it.
2019-07-08 20:20:40 -04:00
For Fish, you can install a plugin for [Fisher ](https://github.com/jorgebucaran/fisher ):
2019-03-16 17:49:59 -04:00
2020-01-30 10:09:15 -05:00
```shell
2019-03-16 17:49:59 -04:00
fisher add fisherman/pyenv
```
Or for [Oh My Fish ](https://github.com/oh-my-fish/oh-my-fish ):
2020-01-30 10:09:15 -05:00
```shell
2019-03-16 17:49:59 -04:00
omf install pyenv
```
## Dependency management
While GitLab doesn't directly contain any Python scripts, because we depend on Python to render
2020-02-03 22:08:37 -05:00
[reStructuredText ](https://docutils.sourceforge.io/rst.html ) markup, we need to keep track on dependencies
2019-03-16 17:49:59 -04:00
on the main project level, so we can run that on our development machines.
Recently, an equivalent to the `Gemfile` and the [Bundler ](https://bundler.io/ ) project has been introduced to Python:
`Pipfile` and [Pipenv ](https://pipenv.readthedocs.io/en/latest/ ).
2020-11-25 22:09:17 -05:00
A `Pipfile` with the dependencies now exists in the root folder. To install them, run:
2019-03-16 17:49:59 -04:00
2020-01-30 10:09:15 -05:00
```shell
2019-03-16 17:49:59 -04:00
pipenv install
```
2020-11-25 22:09:17 -05:00
Running this command installs both the required Python version as well as required pip dependencies.
2019-03-16 17:49:59 -04:00
## Use instructions
2019-08-30 01:56:51 -04:00
To run any Python code under the Pipenv environment, you need to first start a `virtualenv` based on the dependencies
2019-03-16 17:49:59 -04:00
of the application. With Pipenv, this is a simple as running:
2020-01-30 10:09:15 -05:00
```shell
2019-03-16 17:49:59 -04:00
pipenv shell
```
2020-11-25 22:09:17 -05:00
After running that command, you can run GitLab on the same shell and it uses the Python and dependencies
2019-03-16 17:49:59 -04:00
installed from the `pipenv install` command.