Can I move a virtualenv?

后端 未结 7 1476
栀梦
栀梦 2020-11-29 20:30

This question is not a duplicate.

It pertains not just to renaming a virtual environment, but to actually moving it to a different directory, incl

7条回答
  •  时光说笑
    2020-11-29 20:51

    Using answers of this and other threads about similar topic, I've made a bash script that, located and executed within the virtualenv directory itself, will help with your virtualenv moves.

    After doing virtualenv --relocatable yourenv you'll need to change your VIRTUAL_ENV variable every time you move the directory, so if you don't wan't to change it manually, use this.

    #!/bin/bash \n 
    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
    EXISTING=$(grep 'VIRTUAL_ENV=' bin/activate)  
    NEWDIR=VIRTUAL_ENV=\"$DIR\"
    sed -i -e "s|$EXISTING|$NEWDIR|" bin/activate
    source bin/activate
    

    I hope it helps.

提交回复
热议问题