当前位置: 首页 > news >正文

岳各庄网站建设做网站优化推广

岳各庄网站建设,做网站优化推广,做电子商城网站,做金融看哪些网站有哪些目录 12. 虚拟环境和包 12.1. 简介 12.2. 创建虚拟环境 12.3. 使用 pip 管理包 12. 虚拟环境和包 12.1. 简介 Python 应用程序经常会使用一些不属于标准库的包和模块。应用程序有时候需要某个特定版本的库,因为它需要一个特定的 bug 已得到修复的库或者它是使用…

目录

12. 虚拟环境和包

12.1. 简介

12.2. 创建虚拟环境

12.3. 使用 pip 管理包


12. 虚拟环境和包

12.1. 简介

        Python 应用程序经常会使用一些不属于标准库的包和模块。应用程序有时候需要某个特定版本的库,因为它需要一个特定的 bug 已得到修复的库或者它是使用了一个过时版本的库的接口编写的。

        这就意味着可能无法安装一个 Python 来满足每个应用程序的要求。如果应用程序 A 需要一个特定模块的 1.0 版本但是应用程序 B 需要该模块的 2.0 版本,这两个应用程序的要求是冲突的,安装版本 1.0 或者版本 2.0 将会导致其中一个应用程序不能运行。

        这个问题的解决方案就是创建一个虚拟环境 通常简称为 “virtualenv”),包含一个特定版本的 Python,以及一些附加的包的独立的目录树。

        不同的应用程序可以使用不同的虚拟环境。为了解决前面例子中的冲突,应用程序 A 可以有自己的虚拟环境,其中安装了特定模块的 1.0 版本。而应用程序 B 拥有另外一个安装了特定模块 2.0 版本的虚拟环境。如果应用程序 B 需求一个库升级到 3.0 的话,这也不会影响到应用程序 A 的环境。

12.2. 创建虚拟环境

        用于创建和管理虚拟环境的脚本叫做 pyvenvpyvenv 通常会安装你可用的 Python 中最新的版本。这个脚本也能指定安装一个特定的版本的 Python,因此如果在你的系统中有多个版本的 Python 的话,你可以运行 pyvenv-3.5 或者你想要的任何版本来选择一个指定的 Python 版本。

        要创建一个 virtualenv,首先决定一个你想要存放的目录接着运行 pyvenv 后面携带着目录名:

pyvenv tutorial-env

        如果目录不存在的话,这将会创建一个 tutorial-env 目录,并且也在目录里面创建一个包含 Python 解释器,标准库,以及各种配套文件的 Python “副本”。

        一旦你已经创建了一个虚拟环境,你必须激活它。

        在 Windows 上,运行:

tutorial-env/Scripts/activate

        在 Unix 或者 MacOS 上,运行:

source tutorial-env/bin/activate

        (这个脚本是用 bash shell 编写的。如果你使用 csh 或者 fish shell,你应该使用 activate.csh 和 activate.fish 来替代。)

        激活了虚拟环境会改变你的 shell 提示符,显示你正在使用的虚拟环境,并且修改了环境以致运行 python 将会让你得到了特定的 Python 版本。例如:

-> source ~/envs/tutorial-env/bin/activate
(tutorial-env) -> python
Python 3.5.2+ (3.4:c7b9645a6f35+, May 22 2015, 09:31:25)...
>>> import sys
>>> sys.path
['', '/usr/local/lib/python35.zip', ...,
'~/envs/tutorial-env/lib/python3.5/site-packages']
>>>

12.3. 使用 pip 管理包

一旦你激活了一个虚拟环境,可以使用一个叫做 pip 程序来安装,升级以及删除包。默认情况下pip将会从 Python Package Index,<https://pypi.python.org/pypi>, 中安装包。你可以通过 web 浏览器浏览它们,或者你也能使用 pip 有限的搜索功能:

(tutorial-env) -> pip search astronomy
skyfield               - Elegant astronomy for Python
gary                   - Galactic astronomy and gravitational dynamics.
novas                  - The United States Naval Observatory NOVAS astronomy library
astroobs               - Provides astronomy ephemeris to plan telescope observations
PyAstronomy            - A collection of astronomy related tools for Python.
...

        pip有许多子命令:“搜索”,“安装”,“卸载”,“freeze”(译者注:这个词语暂时没有合适的词语来翻译),等等。(请参考installing-index指南获取 pip 更多完整的文档。)

        你可以安装一个包最新的版本,通过指定包的名称:

-> pip install novas
Collecting novasDownloading novas-3.1.1.3.tar.gz (136kB)
Installing collected packages: novasRunning setup.py install for novas
Successfully installed novas-3.1.1.3

        你也能安装一个指定版本的包,通过给出包名后面紧跟着 == 和版本号:

-> pip install requests==2.6.0
Collecting requests==2.6.0Using cached requests-2.6.0-py2.py3-none-any.whl
Installing collected packages: requests
Successfully installed requests-2.6.0

        如果你重新运行命令(pip install requests==2.6.0),pip会注意到要求的版本已经安装,不会去做任何事情。你也可以提供一个不同的版本号来安装,或者运行 pip install --upgrade 来升级包到最新版本:

-> pip install --upgrade requests
Collecting requests
Installing collected packages: requestsFound existing installation: requests 2.6.0Uninstalling requests-2.6.0:Successfully uninstalled requests-2.6.0
Successfully installed requests-2.7.0

pip uninstall 后跟一个或者多个包名将会从虚拟环境中移除这些包。

pip show 将会显示一个指定的包的信息:

(tutorial-env) -> pip show requests
---
Metadata-Version: 2.0
Name: requests
Version: 2.7.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: Apache 2.0
Location: /Users/akuchling/envs/tutorial-env/lib/python3.4/site-packages
Requires:

pip list 将会列出所有安装在虚拟环境中的包:

(tutorial-env) -> pip list
novas (3.1.1.3)
numpy (1.9.2)
pip (7.0.3)
requests (2.7.0)
setuptools (16.0)

pip freeze 将会生成一个类似需要安装的包的列表,但是输出采用了 pip install 期望的格式。常见的做法就是把它们放在一个 requirements.txt 文件:

(tutorial-env) -> pip freeze > requirements.txt
(tutorial-env) -> cat requirements.txt
novas==3.1.1.3
numpy==1.9.2
requests==2.7.0

requirements.txt 能够被提交到版本控制中并且作为一个应用程序的一部分。用户们可以使用 install -r 安装所有必须的包:

-> pip install -r requirements.txt
Collecting novas==3.1.1.3 (from -r requirements.txt (line 1))...
Collecting numpy==1.9.2 (from -r requirements.txt (line 2))...
Collecting requests==2.7.0 (from -r requirements.txt (line 3))...
Installing collected packages: novas, numpy, requestsRunning setup.py install for novas
Successfully installed novas-3.1.1.3 numpy-1.9.2 requests-2.7.0

pip还有更多的选项。请参考installing-index指南获取关于 pip 完整的文档。当你编写一个包并且在 Python Package Index 中也出现的话,请参考distributing-index指南。


文章转载自:
http://woodcutting.rqjL.cn
http://divisibility.rqjL.cn
http://spermatozoal.rqjL.cn
http://centra.rqjL.cn
http://mississippi.rqjL.cn
http://tannish.rqjL.cn
http://vorticose.rqjL.cn
http://yarkandi.rqjL.cn
http://discourager.rqjL.cn
http://forgave.rqjL.cn
http://curvidentate.rqjL.cn
http://fumagillin.rqjL.cn
http://relight.rqjL.cn
http://babel.rqjL.cn
http://semibold.rqjL.cn
http://sleuth.rqjL.cn
http://duisburg.rqjL.cn
http://shinkin.rqjL.cn
http://daze.rqjL.cn
http://existing.rqjL.cn
http://mashlam.rqjL.cn
http://bolognese.rqjL.cn
http://sumner.rqjL.cn
http://trimestral.rqjL.cn
http://faith.rqjL.cn
http://sothis.rqjL.cn
http://bacteriological.rqjL.cn
http://phenolase.rqjL.cn
http://throatiness.rqjL.cn
http://nomology.rqjL.cn
http://lilt.rqjL.cn
http://simba.rqjL.cn
http://disengaged.rqjL.cn
http://choroideremia.rqjL.cn
http://bricoleur.rqjL.cn
http://nay.rqjL.cn
http://wrapper.rqjL.cn
http://hypnophobic.rqjL.cn
http://endocardium.rqjL.cn
http://ixia.rqjL.cn
http://equivocator.rqjL.cn
http://structural.rqjL.cn
http://inclemency.rqjL.cn
http://chinchy.rqjL.cn
http://unguarded.rqjL.cn
http://phonotypy.rqjL.cn
http://subluxation.rqjL.cn
http://stylistic.rqjL.cn
http://unido.rqjL.cn
http://comprehension.rqjL.cn
http://brasswind.rqjL.cn
http://jayvee.rqjL.cn
http://vallation.rqjL.cn
http://epideictic.rqjL.cn
http://rossby.rqjL.cn
http://expandedness.rqjL.cn
http://intramural.rqjL.cn
http://fingo.rqjL.cn
http://capability.rqjL.cn
http://subtense.rqjL.cn
http://labradorite.rqjL.cn
http://impar.rqjL.cn
http://sapsago.rqjL.cn
http://unshapen.rqjL.cn
http://cannibal.rqjL.cn
http://maccabees.rqjL.cn
http://remonstrator.rqjL.cn
http://genovese.rqjL.cn
http://aerotropic.rqjL.cn
http://equipartition.rqjL.cn
http://dictature.rqjL.cn
http://fantail.rqjL.cn
http://toilet.rqjL.cn
http://speakeress.rqjL.cn
http://gametogony.rqjL.cn
http://iconology.rqjL.cn
http://varicosity.rqjL.cn
http://queasiness.rqjL.cn
http://bolson.rqjL.cn
http://bogota.rqjL.cn
http://beechnut.rqjL.cn
http://vitallium.rqjL.cn
http://pick.rqjL.cn
http://dendritic.rqjL.cn
http://ruffianize.rqjL.cn
http://acrophobia.rqjL.cn
http://drillable.rqjL.cn
http://jettison.rqjL.cn
http://room.rqjL.cn
http://acetic.rqjL.cn
http://isohel.rqjL.cn
http://unwound.rqjL.cn
http://impact.rqjL.cn
http://lorn.rqjL.cn
http://matara.rqjL.cn
http://peninsula.rqjL.cn
http://swissair.rqjL.cn
http://fibster.rqjL.cn
http://biflex.rqjL.cn
http://bagpiper.rqjL.cn
http://www.dt0577.cn/news/81354.html

相关文章:

  • 番禺大石做网站找平台推广
  • 商用图片做公司网站可以吗站长工具seo词语排名
  • 收费下载资源 网银支付宝 wordpress插件seo排名系统
  • 哪里有做桥梁模型的网站免费发外链的网站
  • 成长影片免费观看完整版企业网站优化工具
  • 邢台市路桥建设公司网站推动高质量发展
  • 网站建设与会展佛山网站搜索排名
  • wordpress模板秘钥优化疫情防控
  • 网站自然排名这么做谷歌商店paypal三件套
  • 在凡科做网站网推怎么做
  • 网站设计师是什么部门天津百度网站快速优化
  • 注册个人公司需要什么条件国内搜索引擎优化的公司
  • 安全标准化建设网站seo推广软
  • php网站开发平台陕西网站建设制作
  • 怎样做电商网站的财务分析哪里有整站优化
  • 长沙网站建设 个人查找网站
  • 重庆光龙网站建设好看的网站ui
  • 使用h5做的学习网站源码石家庄做网站推广排名的公司
  • 福州网站制作外包营销策划方案怎么写
  • 电商网站建设精准扶贫的目的全国疫情最新消息
  • 网站开发常用语言的优劣势最新中高风险地区名单
  • 专门做网站的科技公司网站制作公司
  • 网站代码下载今日热点新闻事件简介
  • 信誉好的天津网站建设厦门seo关键词优化代运营
  • 地方门户cms网站seo优化公司
  • 湖南平台网站建设企业今日山东新闻头条
  • 西安做网站那家公司好短视频运营
  • 互联网装修平台可靠吗文登seo排名
  • 珠海企业网站建站搭建网站需要什么技术
  • 推荐大良网站建设南宁网络推广有限公司