Last active
January 11, 2017 05:35
-
-
Save i026e/5c216a36e10a2bed32d9cffc60af8c20 to your computer and use it in GitHub Desktop.
Bash script to create python3 virtual environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env sh | |
name="$1" | |
mkdir -p "./$1" | |
mkdir -p "./$1/src" | |
cd "./$1" | |
#pyvenv --system-site-packages --symlinks "$@" | |
pyvenv --symlinks "$@" | |
ln -s "./$1/bin/activate" "./activate" | |
SH_TMPLT="#! /usr/bin/env sh | |
DIR=\"\$( cd \"\$( dirname \"\${BASH_SOURCE[0]}\" )\" && pwd )\" | |
. \$DIR/$1/bin/activate | |
echo using \$(which python3) | |
python3 \$DIR/src/$1.py \"\$@\" | |
deactivate | |
" | |
PIP_TMPLT="#! /usr/bin/env sh | |
DIR=\"\$( cd \"\$( dirname \"\${BASH_SOURCE[0]}\" )\" && pwd )\" | |
. \$DIR/$1/bin/activate | |
echo using \$(which python3) | |
pip3 \"\$@\" | |
deactivate | |
" | |
PY_TMPLT="#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import sys | |
if __name__ == \"__main__\": | |
print(sys.argv) | |
" | |
touch "./$1.sh" | |
echo "$SH_TMPLT" > "./$1.sh" | |
touch "./pip.sh" | |
echo "$PIP_TMPLT" > "./pip.sh" | |
touch "./src/$1.py" | |
echo "$PY_TMPLT" > "./src/$1.py" | |
chmod 755 "./$1.sh" | |
chmod 755 "./pip.sh" | |
. "./$1.sh" test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment