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

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.

主站蜘蛛池模板: 博爱县| 鄱阳县| 通河县| 高碑店市| 南岸区| 高淳县| 桂林市| 酒泉市| 盘山县| 大余县| 丹寨县| 观塘区| 故城县| 商城县| 邻水| 墨玉县| 巴塘县| 昌都县| 河东区| 昔阳县| 搜索| 木里| 格尔木市| 桓仁| 申扎县| 嘉禾县| 平阴县| 海伦市| 太保市| 蒲城县| 佛山市| 天等县| 肥城市| 灵丘县| 宜川县| 松溪县| 西吉县| 监利县| 城步| 分宜县| 陈巴尔虎旗|