{
    "mode": "pydoc",
    "parameter": "venv",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/venv/json",
    "generated": "2026-06-02T13:24:25Z",
    "sections": {
        "NAME": {
            "content": "venv - Virtual environment (venv) package for Python. Based on PEP 405.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/venv.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Copyright (C) 2011-2014 Vinay Sajip.\nLicensed to the PSF under a contributor agreement.\n",
            "subsections": []
        },
        "PACKAGE CONTENTS": {
            "content": "main\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.object\nEnvBuilder\n",
            "subsections": [
                {
                    "name": "class EnvBuilder",
                    "content": "|  EnvBuilder(systemsitepackages=False, clear=False, symlinks=False, upgrade=False, withpip=False, prompt=None, upgradedeps=False)\n|\n|  This class exists to allow virtual environment creation to be\n|  customized. The constructor parameters determine the builder's\n|  behaviour when called upon to create a virtual environment.\n|\n|  By default, the builder makes the system (global) site-packages dir\n|  *un*available to the created environment.\n|\n|  If invoked using the Python -m option, the default is to use copying\n|  on Windows platforms but symlinks elsewhere. If instantiated some\n|  other way, the default is to *not* use symlinks.\n|\n|  :param systemsitepackages: If True, the system (global) site-packages\n|                               dir is available to created environments.\n|  :param clear: If True, delete the contents of the environment directory if\n|                it already exists, before environment creation.\n|  :param symlinks: If True, attempt to symlink rather than copy files into\n|                   virtual environment.\n|  :param upgrade: If True, upgrade an existing virtual environment.\n|  :param withpip: If True, ensure pip is installed in the virtual\n|                   environment\n|  :param prompt: Alternative terminal prefix for the environment.\n|  :param upgradedeps: Update the base venv modules to the latest on PyPI\n|\n|  Methods defined here:\n|\n|  init(self, systemsitepackages=False, clear=False, symlinks=False, upgrade=False, withpip=False, prompt=None, upgradedeps=False)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  cleardirectory(self, path)\n|\n|  create(self, envdir)\n|      Create a virtual environment in a directory.\n|\n|      :param envdir: The target directory to create an environment in.\n|\n|  createconfiguration(self, context)\n|      Create a configuration file indicating where the environment's Python\n|      was copied from, and whether the system site-packages should be made\n|      available in the environment.\n|\n|      :param context: The information for the environment creation request\n|                      being processed.\n|\n|  ensuredirectories(self, envdir)\n|      Create the directories for the environment.\n|\n|      Returns a context object which holds paths in the environment,\n|      for use by subsequent logic.\n|\n|  installscripts(self, context, path)\n|      Install scripts into the created environment from a directory.\n|\n|      :param context: The information for the environment creation request\n|                      being processed.\n|      :param path:    Absolute pathname of a directory containing script.\n|                      Scripts in the 'common' subdirectory of this directory,\n|                      and those in the directory named for the platform\n|                      being run on, are installed in the created environment.\n|                      Placeholder variables are replaced with environment-\n|                      specific values.\n|\n|  postsetup(self, context)\n|      Hook for post-setup modification of the venv. Subclasses may install\n|      additional packages or scripts here, add activation shell scripts, etc.\n|\n|      :param context: The information for the environment creation request\n|                      being processed.\n|\n|  replacevariables(self, text, context)\n|      Replace variable placeholders in script text with context-specific\n|      variables.\n|\n|      Return the text passed in , but with variables replaced.\n|\n|      :param text: The text in which to replace placeholder variables.\n|      :param context: The information for the environment creation request\n|                      being processed.\n|\n|  setuppython(self, context)\n|      Set up a Python executable in the environment.\n|\n|      :param context: The information for the environment creation request\n|                      being processed.\n|\n|  setupscripts(self, context)\n|      Set up scripts into the created environment from a directory.\n|\n|      This method installs the default scripts into the environment\n|      being created. You can prevent the default installation by overriding\n|      this method if you really need to, or if you need to specify\n|      a different location for the scripts to install. By default, the\n|      'scripts' directory in the venv package is used as the source of\n|      scripts to install.\n|\n|  symlinkorcopy(self, src, dst, relativesymlinksok=False)\n|      Try symlinking a file, and if that fails, fall back to copying.\n|\n|  upgradedependencies(self, context)\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "create",
                    "content": "Create a virtual environment in a directory.\n"
                },
                {
                    "name": "main",
                    "content": ""
                }
            ]
        },
        "DATA": {
            "content": "COREVENVDEPS = ('pip', 'setuptools')\nlogger = <Logger venv (WARNING)>\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/venv/init.py\n\n",
            "subsections": []
        }
    },
    "summary": "venv - Virtual environment (venv) package for Python. Based on PEP 405.",
    "flags": [],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Create lightweight virtual environments in Python.",
        "examples": [
            {
                "description": "Create a Python virtual environment",
                "command": "python -m venv {{path/to/virtual_environment}}"
            },
            {
                "description": "Activate the virtual environment (Linux and macOS)",
                "command": "{{.|source}} {{path/to/virtual_environment}}/bin/activate"
            },
            {
                "description": "Activate the virtual environment (Windows)",
                "command": "{{path\\to\\virtual_environment}}\\Scripts\\activate.bat"
            },
            {
                "description": "Deactivate the virtual environment",
                "command": "deactivate"
            },
            {
                "description": "Create an alias that generates a `venv` folder and automatically activates it",
                "command": "alias venv='python -m venv .venv && source {{.venv/bin/activate|.venv\\Scripts\\activate.bat}}'"
            }
        ]
    }
}