Skip to content

Instantly share code, notes, and snippets.

@VishalTaj
Last active March 23, 2017 07:31
Show Gist options
  • Save VishalTaj/03913a6617ab6ec87341 to your computer and use it in GitHub Desktop.
Save VishalTaj/03913a6617ab6ec87341 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
__author__ = 'Vishal Taj PM'
import subprocess
import os
import shutil
def create_virtualenv(envName):
subprocess.call(['virtualenv', envName])
def install(packageName):
subprocess.call('pip','install',packageName)
def workon(envName):
shutil.copy2('script.py', envName+'/script.py')
os.chdir(envName+'/')
os.system('/bin/bash --rcfile '+activate)
subprocess.Popen([python_bin, script_file])
def deactivate():
subprocess.call('source', 'bin/deactivate')
path = os.getcwd()
envName = raw_input("Virtual Environment Name : ")
python_bin = path+'/'+envName+"/bin/python"
activate = path+'/'+envName+'/bin/activate'
# path to the script that must run under the virtualenv
script_file = path+"/script.py"
if not os.path.isdir(envName):
create_virtualenv(envName)
workon(envName)
else:
workon(envName)
print """A Directory with the same name already exist please specify
other name or remove it manually"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment