ERROR virtualenvwrapper in GitBash

£可爱£侵袭症+ 提交于 2019-12-01 07:01:50

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!