Python. урок 17. виртуальные окружения


Виртуальные окружения создаются с помощью virtualenvwrapper.

Установка virtualenvwrapper с помощью pip:

$ sudo pip3.7 install virtualenvwrapper

После установки, в файле .bashrc, находящимся в домашней папке текущего
пользователя, нужно добавить несколько строк:

export VIRTUALENVWRAPPER_PYTHON=/usrlocalbinpython3.7
export WORKON_HOME=~/venv

Если вы используете командный интерпретатор, отличный от bash,
посмотрите, поддерживается ли он в
virtualenvwrapper. Переменная окружения VIRTUALENVWRAPPER_PYTHON
указывает на бинарный файл командной строки Python, WORKON_HOME – на
расположение виртуальных окружений. Третья строка указывает, где
находится скрипт, установленный с пакетом virtualenvwrapper. Для того,
чтобы скрипт выполнился и можно было работать с
виртуальными окружениями, надо перезапустить bash.

Перезапуск командного интерпретатора:

$ exec bash

Copies versus symlinks

The technique in this PEP works equally well in general with a copied
or symlinked Python binary (and other needed DLLs on Windows).
Symlinking is preferable where possible, because in the case of an
upgrade to the underlying Python installation, a Python executable
copied in a venv might become out-of-sync with the installed standard
library and require manual upgrade.

There are some cross-platform difficulties with symlinks:

  • Not all Windows versions support symlinks, and even on those that
    do, creating them often requires administrator privileges.
  • On OS X framework builds of Python, sys.executable is just a stub
    that executes the real Python binary. Symlinking this stub does not
    work; it must be copied. (Fortunately the stub is also small, and
    not changed by bugfix upgrades to Python, so copying it is not an

Thus, this PEP proposes to symlink the binary on all platforms except
for Windows, and OS X framework builds. A --symlink option is
available to force the use of symlinks on Windows versions that
support them, if the appropriate permissions are available. (This
option has no effect on OS X framework builds, since symlinking can
never work there, and has no advantages).


  • Update the list of discoverable Python versions:
  • To view a list of python versions supported by pyenv windows:
  • To install a python version:
    • Note: An install wizard may pop up for some non-silent installs. You’ll need to click through the wizard during installation. There’s no need to change any options in it. or you can use -q for quite installation
    • You can also install multiple versions in one command too:
  • To set a python version as the global version:
    • This is the version of python that will be used by default if a local version (see below) isn’t set.
    • Note: The version must first be installed.
  • To set a python version as the local version: .
    • The version given will be used whenever is called from within this folder. This is different than a virtual env, which needs to be explicitly activated.
    • Note: The version must first be installed.
  • After (un)installing any libraries using pip or modifying the files in a version’s folder, you must run to update pyenv with new shims for the python and libraries’ executables.
  • To uninstall a python version:
  • To view which python you are using and its path:
  • To view all the python versions installed on this system:
Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *