mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
translated
This commit is contained in:
parent
7cbde9649e
commit
d3327e8199
@ -1,95 +0,0 @@
|
|||||||
translating---geekpi
|
|
||||||
|
|
||||||
How to install Pipenv on Fedora
|
|
||||||
======
|
|
||||||
|
|
||||||
![](https://fedoramagazine.org/wp-content/uploads/2018/06/pipenv-install-816x345.jpg)
|
|
||||||
|
|
||||||
Pipenv aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. It tries to solve a couple of problems and also simplify the whole management process.
|
|
||||||
|
|
||||||
Currently the management of Python application dependencies sometimes seems like a bit of a challenge. Developers usually create a [virtual environment][1] for each new project and install dependencies into it using [pip][2]. In addition they have to store the set of installed packages into the requirements.txt text file. We’ve seen many tools and wrappers that aim to automate this workflow. However, there was still necessity to combine multiple utilities and the requirements.txt format itself is not ideal for more complicated scenarios.
|
|
||||||
|
|
||||||
### One tol to rule them all
|
|
||||||
|
|
||||||
Pipenv manages complex inter-dependencies properly and it also provides manual documenting of installed packages. For example development, testing and production environments often require a different set of packages. It used to be necessary to maintain multiple requirements.txt per project. Pipenv introduces the new [Pipfile][3] format using [TOML][4] syntax. Thanks to this format, you can finally maintain multiple set of requirement for different environments in a single file.
|
|
||||||
|
|
||||||
Pipenv has become the officially recommended tool for managing Python application dependencies only a year after the first lines of code were committed into the project. Now it is finally available as an package in Fedora repositories as well.
|
|
||||||
|
|
||||||
### Installing Pipenv on Fedora
|
|
||||||
|
|
||||||
On clean installation of Fedora 28 and later you can simply install Pipenv by running this command at the terminal:
|
|
||||||
```
|
|
||||||
$ sudo dnf install pipenv
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Your system is now ready to start working on your new Python 3 application with help of Pipenv.
|
|
||||||
|
|
||||||
The important point is that while this tool provides nice solution for the applications, it is not designed for dealing with library requirements. When writing a Python library, pinning dependencies is not desirable. You should rather specify install_requires in setup.py file.
|
|
||||||
|
|
||||||
### Basic dependencies management
|
|
||||||
|
|
||||||
Create a directory for your project first:
|
|
||||||
```
|
|
||||||
$ mkdir new-project && cd new-project
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Another step is to create a virtual environment for this project:
|
|
||||||
```
|
|
||||||
$ pipenv --three
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
The –three option here sets the Python version of the virtual environment to Python 3.
|
|
||||||
|
|
||||||
Install dependencies:
|
|
||||||
```
|
|
||||||
$ pipenv install requests
|
|
||||||
Installing requests…
|
|
||||||
Adding requests to Pipfile's [packages]…
|
|
||||||
Pipfile.lock not found, creating…
|
|
||||||
Locking [dev-packages] dependencies…
|
|
||||||
Locking [packages] dependencies…
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally generate a lockfile:
|
|
||||||
```
|
|
||||||
$ pipenv lock
|
|
||||||
Locking [dev-packages] dependencies…
|
|
||||||
Locking [packages] dependencies…
|
|
||||||
Updated Pipfile.lock (b14837)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also check a dependency graph:
|
|
||||||
```
|
|
||||||
$ pipenv graph
|
|
||||||
- certifi [required: >=2017.4.17, installed: 2018.4.16]
|
|
||||||
- chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4]
|
|
||||||
- idna [required: <2.8,>=2.5, installed: 2.7]
|
|
||||||
- urllib3 [required: >=1.21.1,<1.24, installed: 1.23]
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
More details on Pipenv and it commands are available in the [documentation][5].
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://fedoramagazine.org/install-pipenv-fedora/
|
|
||||||
|
|
||||||
作者:[Michal Cyprian][a]
|
|
||||||
选题:[lujun9972](https://github.com/lujun9972)
|
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]:https://fedoramagazine.org/author/mcyprian/
|
|
||||||
[1]:https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments
|
|
||||||
[2]:https://developer.fedoraproject.org/tech/languages/python/pypi-installation.html
|
|
||||||
[3]:https://github.com/pypa/pipfile
|
|
||||||
[4]:https://github.com/toml-lang/toml
|
|
||||||
[5]:https://docs.pipenv.org/
|
|
93
translated/tech/20180625 How to install Pipenv on Fedora.md
Normal file
93
translated/tech/20180625 How to install Pipenv on Fedora.md
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
如何在 Fedora 上安装 Pipenv
|
||||||
|
======
|
||||||
|
|
||||||
|
![](https://fedoramagazine.org/wp-content/uploads/2018/06/pipenv-install-816x345.jpg)
|
||||||
|
|
||||||
|
Pipenv 的目标是将最好的打包世界(bundler、composer、npm、cargo、yarn 等)带到 Python 世界。它试图解决一些问题,并简化整个管理过程。
|
||||||
|
|
||||||
|
目前,Python 程序依赖项的管理有时似乎是一个挑战。开发人员通常为每个新项目创建一个[虚拟环境][1],并使用 [pip][2] 将依赖项安装到其中。此外,他们必须将已安装的软件包集保存到 requirements.txt 文件中。我们看到过许多旨在自动化此工作流程的工具和包装程序。但是,仍然需要结合多个程序,并且 requirements.txt 格式本身并不适用于更复杂的场景。
|
||||||
|
|
||||||
|
### 一个统治它们的工具
|
||||||
|
|
||||||
|
Pipenv 正确地管理复杂的相互依赖关系,它还提供已安装包的手动记录。例如,开发、测试和生产环境通常需要一组不同的包。过去,每个项目需要维护多个 requirements.txt。Pipenv 使用 [TOML][4] 语法引入了新的 [Pipfile][3] 格式。多亏这种格式,你终于可以在单个文件中维护不同环境的多组需求。
|
||||||
|
|
||||||
|
在将第一行代码提交到项目中仅一年后,Pipenv 已成为管理 Python 程序依赖关系的官方推荐工具。现在它终于在 Fedora 仓库中提供。
|
||||||
|
|
||||||
|
### 在 Fedora 上安装 Pipenv
|
||||||
|
|
||||||
|
在全新安装 Fedora 28 及更高版本后,你只需在终端上运行此命令即可安装 Pipenv:
|
||||||
|
```
|
||||||
|
$ sudo dnf install pipenv
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
现在,你的系统已准备好在 Pipenv 的帮助下开始使用新的 Python 3 程序。
|
||||||
|
|
||||||
|
重要的是,虽然这个工具为程序提供了很好的解决方案,但它并不是为处理库需求而设计的。编写 Python 库时,不需要固定依赖项。你应该在 setup.py 文件中指定 install_requires。
|
||||||
|
|
||||||
|
### 基本依赖管理
|
||||||
|
|
||||||
|
首先为项目创建一个目录:
|
||||||
|
```
|
||||||
|
$ mkdir new-project && cd new-project
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
接下来是为此项目创建虚拟环境:
|
||||||
|
```
|
||||||
|
$ pipenv --three
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
这里的 -three 选项将虚拟环境的 Python 版本设置为 Python 3。
|
||||||
|
|
||||||
|
安装依赖项:
|
||||||
|
```
|
||||||
|
$ pipenv install requests
|
||||||
|
Installing requests…
|
||||||
|
Adding requests to Pipfile's [packages]…
|
||||||
|
Pipfile.lock not found, creating…
|
||||||
|
Locking [dev-packages] dependencies…
|
||||||
|
Locking [packages] dependencies…
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
最后生成 lockfile:
|
||||||
|
```
|
||||||
|
$ pipenv lock
|
||||||
|
Locking [dev-packages] dependencies…
|
||||||
|
Locking [packages] dependencies…
|
||||||
|
Updated Pipfile.lock (b14837)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
你还可以检查依赖关系图:
|
||||||
|
```
|
||||||
|
$ pipenv graph
|
||||||
|
- certifi [required: >=2017.4.17, installed: 2018.4.16]
|
||||||
|
- chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4]
|
||||||
|
- idna [required: <2.8,>=2.5, installed: 2.7]
|
||||||
|
- urllib3 [required: >=1.21.1,<1.24, installed: 1.23]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
有关 Pipenv 及其命令的更多详细信息,请参见[文档][5]。
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://fedoramagazine.org/install-pipenv-fedora/
|
||||||
|
|
||||||
|
作者:[Michal Cyprian][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[geekpi](https://github.com/geekpi)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]:https://fedoramagazine.org/author/mcyprian/
|
||||||
|
[1]:https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments
|
||||||
|
[2]:https://developer.fedoraproject.org/tech/languages/python/pypi-installation.html
|
||||||
|
[3]:https://github.com/pypa/pipfile
|
||||||
|
[4]:https://github.com/toml-lang/toml
|
||||||
|
[5]:https://docs.pipenv.org/
|
Loading…
Reference in New Issue
Block a user