官术网_书友最值得收藏!

Implementing virtual Python environments

As touched on previously, Python virtual environments create separate Python environments, much like virtual machines allow multiple but separate operating systems. Python virtual environments are particularly useful when installing multiple
instances of the same module.

For example, assume you are working on a project that requires version 1.2 of a particular library module for legacy support. Now assume you download a Python program that uses version 2.2 of the same library. If you install everything in the default global location on your hard drive, for example, /usr/lib/python3.6/site-packages, the new program will install the updated library into the same location, overwriting the legacy software. Since you were using an old library for legacy support, there's a good chance that the updated library will break your application.

Also, on shared systems (especially if you don't have admin rights), there is a strong possibility that you simply can't install modules on the system, at least not in the default global site-packages directory. You may luck out and be able to install software for your account but, if you can't, you have to either request permission to install it or go without.

This is where virtual Python environments come into play. Each environment has its own installation directories and there is no sharing of libraries between environments. This means that each version of a module within an environment stays the same, even if you update global libraries. It also means you can have multiple versions of modules installed on your computer at the same time without having conflicts.

Virtual environments have their own shells as well, allowing access to an OS shell that is independent of any other environment or the underlying operating system. This recipe also shows how to spawn a new Python shell from pipenv. Doing this ensures all commands will have access to the installed packages within the virtual environment.

主站蜘蛛池模板: 威宁| 进贤县| 江川县| 昌吉市| 旺苍县| 巴林右旗| 紫云| 博客| 卢湾区| 赤水市| 万安县| 资讯 | 新源县| 龙口市| 尉犁县| 吉林市| 东山县| 盈江县| 长春市| 海盐县| 金华市| 大石桥市| 金塔县| 香港| 安图县| 自治县| 镇赉县| 淄博市| 建平县| 长治县| 出国| 天镇县| 元氏县| 织金县| 建平县| 永宁县| 天等县| 通道| 会理县| 巴南区| 敖汉旗|