{"id":20384973,"url":"https://github.com/d-e-s-o/pyvenv-auto","last_synced_at":"2026-04-06T08:31:38.786Z","repository":{"id":83738656,"uuid":"49315511","full_name":"d-e-s-o/pyvenv-auto","owner":"d-e-s-o","description":"Fully automated activation of Python virtual environments.","archived":false,"fork":false,"pushed_at":"2019-05-12T17:37:21.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"devel","last_synced_at":"2025-03-04T23:14:20.788Z","etag":null,"topics":["python","python-venv","python-virtual-environment","python3"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d-e-s-o.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-09T07:37:04.000Z","updated_at":"2024-11-17T21:37:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d2c5f73-9f3f-42d7-befd-dbf4f3e20ff0","html_url":"https://github.com/d-e-s-o/pyvenv-auto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/d-e-s-o/pyvenv-auto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Fpyvenv-auto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Fpyvenv-auto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Fpyvenv-auto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Fpyvenv-auto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d-e-s-o","download_url":"https://codeload.github.com/d-e-s-o/pyvenv-auto/tar.gz/refs/heads/devel","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-e-s-o%2Fpyvenv-auto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31464604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","python-venv","python-virtual-environment","python3"],"created_at":"2024-11-15T02:31:05.147Z","updated_at":"2026-04-06T08:31:38.542Z","avatar_url":"https://github.com/d-e-s-o.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"pyvenv-auto\n===========\n\n\nPurpose\n-------\n\n**pyvenv-auto** is a simple script that can be used to automatically\ndetect and activate a Python virtual environment (*venv*) as proposed in\nPEP 405 in shell environments.\n\nThe program works by overwriting the ``cd`` built-in and enhancing it\nwith a quick check whether the directory being changed into is part of a\nvirtual environment and activating or deacting it accordingly.\n\n\nUsage\n-----\n\nAfter installation as described below, the script itself is activated\nwhenever a new shell is started. From a user perspective everything\nhappens without any additional work: whenever a ``cd`` is performed a\ncheck whether the destination describes a virtual environment is\nperformed. If a valid *venv* structure is found, the virtual environment\nwill be activated by sourcing the respective ``activate`` file\n(``\u003cvenv\u003e/bin/activate``). If a *venv* was already active and we left\nit, the former environment will be deactivated.\n\n### Deactivation\nIf, say, for the purpose of testing, **pyvenv-auto** needs to be\ndisabled, this can happen on a per-shell basis by resetting ``cd`` to\nreference the built-in of the same name rather than the function\nprovided by the program. This binding can be reverted by using:\n\n``$ unset cd``\n\n### Virtual Environments\nIn Python, virtual environments can be created using the following\ncommand:\n\n``$ python -m venv \u003cdirectory\u003e``\n\nThe ``pyvenv`` script serves the same purpose but got deprecated in\nPython 3.6:\n\n``$ pyvenv \u003cdirectory\u003e``\n\n\nInstallation\n------------\n\nThe installation of **pyvenv-auto** is as simple as copying the\n``pyvenv-auto.sh`` into an arbitrary location on the file system. In\norder to activate it it needs to be sourced. This sourcing would\ntypically happen in some shell initialization file. A common candidate\nis ``~/.bashrc``.\n\nIn addition to sourcing it, the ``_pyvenv_activate_deactivate`` function\nmay be invoked afterwards if there is a chance that the current working\ndirectory already contains a virtual environment that should be\nactivated. If the function were not invoked, a ``cd .`` from the newly\nstarted shell accomplishes the same thing.\n\nIn summary, the following lines should be added to your ``~/.bashrc``\nfile:\n\n```\nsource \u003cpath-to-pyvent-auto\u003e/pyvenv-auto.sh\n_pyvenv_activate_deactivate\n```\n\nIf you are using [Gentoo Linux](https://www.gentoo.org/),\nthere is an [ebuild](https://github.com/d-e-s-o/pyvenv-auto-ebuild)\navailable that can be used to install the program in the system (the\nregistration with the bash initialization file still has to be done\nmanually).\n\n\nShell Prompt\n------------\n\nNote that this section is not specific to **pyvenv-auto** in any way. It\nmerely summarizes a problem occuring in the default configuration when\nactivating a Python *venv* and proposes a solution for it.\n\nBy default, Python virtual environments change the command line prompt\n(represented by the ``PS1`` environment variable in typical shell\nenvironments) when activated to reflect the currently active venv (if\nany). However, the are cases where other facilities also overwrite the\nprompt, resulting in a clash.\n\nFor example, consider the an environment where ``git-prompt.sh`` is\nused to indicate the status of the currently \"active\" ``git``\nrepository's status in the prompt.\n\nIn order to solve this problem the *venv* specific prompt change should\nbe deactivated. This deactivation can happen by setting the\n``VIRTUAL_ENV_DISABLE_PROMPT`` environment variable to a non-empty\nstring. Furthermore, the ``PROMPT_COMMAND`` variable which is executed\nby the shell (bash in this case; other shells may or may not have a\nsimilar mechanism) before displaying of the prompt should point to a\nfunction capable of creating a prompt combining the otherwise clashing\nprompt strings.\n\nFor ``git`` and a virtual environment (which could be activated by\n**pyvenv-auto**), such a function could look as follows:\n```bash\nfunction _prompt()\n{\n  local venv_ps1=\"\"\n  # Check if there is a Python venv active.\n  if [ -n \"${VIRTUAL_ENV}\" ]; then\n    # If so, then include its name in the prompt.\n    venv_ps1=\"[$(basename ${VIRTUAL_ENV})] \"\n  fi\n\n  __git_ps1 \"${GREEN}\\u@\\h${BLUE} ${venv_ps1}\\w\" \" \\$${BLACK} \" \" (%s${BLUE})\"\n}\n\nPROMPT_COMMAND=\"_prompt\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-e-s-o%2Fpyvenv-auto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-e-s-o%2Fpyvenv-auto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-e-s-o%2Fpyvenv-auto/lists"}