Git Bash:如何在激活虚拟环境时更改目录

3

使用virtualenvwrapper在Python 3.6.1上创建虚拟环境,使用Git Bash mingw64终端,Win7。

当我激活特定的虚拟环境时,如何自动将工作目录更改为另一个位置?

例如:当我运行workon temp_env时,我希望工作目录被更改为cd "/c/Users/me/Desktop/temp_env"


1
你是否正在使用 virtualenvwrapper?我猜是的,因为你提到了 workon。如果是这样,请阅读此处的文档,其中提到你可以使用 workon -c env_name 或设置一个环境变量 VIRTUALENVWRAPPER_WORKON_CD - Adam Smith
是的,我正在使用virtualenvwrapper。谢谢提供链接。 - Korean_Of_the_Mountain
1个回答

2

我希望设置一个工作目录,它会自动切换到特定虚拟环境定义的位置。

  1. After installing virtualenvwrapper I added following lines to ~/.bashrc per the docs

    export WORKON_HOME=$HOME/.virtualenvs
    source virtualenvwrapper.sh
    
  2. Then I created a new virtual env: mkvirtualenv temp_env

  3. Inside the $HOME/.virtualenvs/temp_env directory, I added a line to the postactivate script (which was created with the virtual env) to change working directory

     cd "/path/to/folder/"
    

有关在激活、停用虚拟环境时定义行为的更多信息,请单击此处


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接