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

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.

主站蜘蛛池模板: 连云港市| 泰兴市| 博客| 连城县| 讷河市| 门源| 萨嘎县| 安康市| 陵水| 扎囊县| 盐边县| 广丰县| 北宁市| 阿图什市| 溆浦县| 南皮县| 周至县| 江都市| 印江| 铜陵市| 个旧市| 肇州县| 郴州市| 蕲春县| 贺兰县| 平潭县| 久治县| 恩平市| 文化| 诏安县| 内江市| 宁晋县| 肥城市| 临夏市| 固阳县| 响水县| 胶州市| 台山市| 类乌齐县| 赤峰市| 武定县|