多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Python Development Guidelines > 原文:[https://docs.gitlab.com/ee/development/python_guide/](https://docs.gitlab.com/ee/development/python_guide/) * [Installation](#installation) * [macOS](#macos) * [Linux](#linux) * [Shell integration](#shell-integration) * [Dependency management](#dependency-management) * [Use instructions](#use-instructions) # Python Development Guidelines[](#python-development-guidelines "Permalink") GitLab requires Python as a dependency for [reStructuredText](https://docutils.sourceforge.io/rst.html) markup rendering. 从 GitLab 11.10 开始,我们需要 Python 3. ## Installation[](#installation "Permalink") 有几种方法可以在系统上安装 Python. 为了能够使用生产中使用的相同版本,建议您使用[pyenv](https://github.com/pyenv/pyenv) . 它的工作方式和行为与 Ruby 世界中的[同类产品 rbenv 相似](https://github.com/rbenv/rbenv) . ### macOS[](#macos "Permalink") 要在 macOS 上安装`pyenv` ,可以将[Homebrew](https://brew.sh/)与以下软件配合使用: ``` brew install pyenv ``` ### Linux[](#linux "Permalink") 要在 Linux 上安装`pyenv` ,您可以运行以下命令: ``` curl https://pyenv.run | bash ``` 另外,您可以通过发行版软件包管理器找到`pyenv`作为系统软件包. 您可以在以下[网址](https://github.com/pyenv/pyenv-installer#prerequisites)了解更多信息: [https](https://github.com/pyenv/pyenv-installer#prerequisites) : [//github.com/pyenv/pyenv-installer#prerequisites](https://github.com/pyenv/pyenv-installer#prerequisites) . ### Shell integration[](#shell-integration "Permalink") Pyenv 安装会将必需的更改添加到 Bash. 如果使用其他外壳,请检查是否需要其他步骤. 对于 Fish,您可以为[Fisher](https://github.com/jorgebucaran/fisher)安装插件: ``` fisher add fisherman/pyenv ``` 还是为了[我的鱼](https://github.com/oh-my-fish/oh-my-fish) : ``` omf install pyenv ``` ## Dependency management[](#dependency-management "Permalink") 尽管 GitLab 不直接包含任何 Python 脚本,但是由于我们依赖 Python 来呈现[reStructuredText](https://docutils.sourceforge.io/rst.html)标记,因此我们需要在主项目级别上跟踪依赖项,以便可以在开发机器上运行它. 最近,Python 引入了与`Gemfile`和[Bundler](https://bundler.io/)项目等效的项目: `Pipfile`和[Pipenv](https://pipenv.readthedocs.io/en/latest/) . 现在,您将在根文件夹中找到具有相关性的`Pipfile` . 要安装它们,请运行: ``` pipenv install ``` 运行此命令将安装所需的 Python 版本以及所需的 pip 依赖项. ## Use instructions[](#use-instructions "Permalink") 要在 Pipenv 环境下运行任何 Python 代码,您需要首先根据应用程序的依赖关系启动`virtualenv` . 使用 Pipenv,运行起来很简单: ``` pipenv shell ``` 运行该命令后,您可以在同一外壳上运行 GitLab,它将使用从`pipenv install`命令安装的 Python 和依赖项.