ERROR virtualenvwrapper in GitBash

后端 未结 2 824
無奈伤痛
無奈伤痛 2021-01-13 20:08

I trying to setup virtualenvwrapper in GitBash (Windows 7). I write the next lines: 1 $ export WORKON_HOME=$HOME/.virtualenvs 2 $ export MSYS_HOME=/c/msys/1.0 3 $

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 20:49

    I've found a fix for this problem on a Windows 8 machine using GitBash.

    TL;DR:

    Get mktemp for windows, put it somewhere that can be used by GitBash, then edit virtualenvwrapper.sh and on line 202, add a touch command with the file created. It should look like this:

    file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)"
    touch $file  # this is the new line
    if [ $? -ne 0 ] || [ -z "$file" ] || [ ! -f "$file" ]
    

    FULL ANSWER:

    As khampson mentioned, you do have to download mktemp and place it where your Git\bin (C:\Program Files (x86)\Git\bin usually) directory is. After that, running the virtualenvwrapper.sh file would cause an error saying:

    path = C:/Users/User/AppData/Local/Temp/virtualenvwrapper-initialize-hook-XXXXXX XXXX 
    lpPathBuffer = C:\Users\User\AppData\Local\Temp\ 
    szTempName = C:\Users\User\AppData\Local\Temp\tmp23A9.tmp 
    path = C:\Users\User\AppData\Local\Temp\tmp23A9.tmp 
    fd = 3 
    ERROR: virtualenvwrapper could not create a temporary file name.
    

    On line 202(source), you see a function call to virtualenvwrapper_mktemp (which is just a wrapper function to call mktemp) and this is supposed to create the new temp file, but apparently it doesn't on windows.

    Going through the manual for mktemp, on the examples section, you see that they are always sending something to that new file handle which forces the file to be created.

    So instead of sending an empty string using echo like the manual, just add a touch command to the virtualenvwrapper.sh:

    file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)"
    touch $file   # new command here
    

    This should force windows to create the temp file. I can't post the rest of the links due to low rep but I hope this still helps someone.

    EDIT

    I created a pull request on the virtualenvwrapper repo and it got approved. You can see the touch command I suggested added here.

提交回复
热议问题