ERROR virtualenvwrapper in GitBash

后端 未结 2 788
無奈伤痛
無奈伤痛 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:30

    The error is saying that sh.exe (the shell) can't find a command matching mktemp, which means it's not present in GitBash, at least not in your environment.

    One option is you could download a Windows version of mktemp, such as http://gnuwin32.sourceforge.net/packages/mktemp.htm and then place it in the C:\Program Files (x86)\Git\bin directory. The shell should then be able to match the mktemp command and be able to proceed.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题