Wiki source code of VirtualEnv

Version 4.1 by David De La Harpe Golden on 2026/05/17 16:13

Hide last authors
David De La Harpe Golden 1.1 1 While historically I use python virtualenv helpers like
2
3 * [[vex>>https://pypi.org/project/vex/]]
4 * [[virtualenvwrapper>>https://pypi.org/project/virtualenvwrapper/]]
5 * [[virtualenvwrapper-win>>https://pypi.org/project/virtualenvwrapper-win/]]
6
7 ...since virtualenv is now in the python stdlib, I have lately pared it down to two little helpers
8
9 * ##mkve## - makes a new basic virtualenv.
10 * ##ve## - launches a subshell with the virtualenv active - in contrast to the weird way official activate does it your _current_ shell i.e like vex but less fancy.
11
12 {{code language="bash"}}
13
14
15 == mkve ==
16
17 {{code language="bash"}}
18 #!/bin/bash
19
20 if [ -e "$1" ] ; then
21 echo >&2 "Already exists. Use python -m venv ... directly for complex args."
22 else
23 exec python -m venv "$1"
24 fi
25
David De La Harpe Golden 3.1 26 {{/code}}
27
David De La Harpe Golden 1.1 28
David De La Harpe Golden 4.1 29
David De La Harpe Golden 1.1 30 {{code language="bash"}}
David De La Harpe Golden 3.1 31
David De La Harpe Golden 1.1 32 #!/bin/bash
33
34 if [ -f "$1/bin/activate" ]; then
35 exec bash --rcfile <(cat ~/.bashrc $1/bin/activate)
36 else
37 echo >&2 "Missing Python Virtual Env (should have venv/bin/activate script)"
38 fi
39
David De La Harpe Golden 3.1 40 {{/code}}
David De La Harpe Golden 1.1 41
42
David De La Harpe Golden 3.1 43