Skip to Content
Python实用技能学习指南
book

Python实用技能学习指南

by Posts & Telecom Press, Robert Smallshire, Austin Bingham
February 2024
Intermediate to advanced
316 pages
3h 47m
Chinese
Packt Publishing
Content preview from Python实用技能学习指南

附录A 虚拟环境

虚拟环境(virtual environment)是一个轻量级、包含Python的安装环境。虚拟环境的主要功能是允许不同的项目来控制已安装的Python包的版本,这不会干扰安装在同一主机上的其他Python项目。虚拟环境由一个目录组成,该目录包含一个现有Python安装的符号链接(UNIX)或一个副本(Windows),并且还包括一个空的site-packages目录,在这个目录中你可以安装特定于这个虚拟环境的Python包。虚拟环境的第二个功能是用户可以创建一个虚拟环境而无须系统管理员的权限,从而让用户可以方便地在本地安装软件包。第三个功能是不同的虚拟环境可以基于不同的Python版本,从而可以让用户更容易地在同一台计算机上测试Python 3.4和Python 3.5的代码。

如果使用Python 3.3或更高版本,那么你的系统上应该已经有了一个名为venv的模块。你可以通过在命令行运行以下代码来验证这一点:

$ python3 -m venv
usage: venv [-h] [--system-site-packages] [--symlinks | --copies]\
[--clear] [--upgrade] [--without-pip]
ENV_DIR [ENV_DIR ...]
venv: error: the following arguments are required: ENV_DIR

如果没有安装venv,那么还有另一个工具——virtualenv环境变量可供选择,它们的工作原理非常相似。你可以从Python包索引(PyPI)中得到它。我们将在附录C中讲解如何从PyPI中安装第三方软件包。你可以使用venv或者virtualenv ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9781835889626