4

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 $ source /usr/local/bin/virtualenvwrapper.sh

And the last line give me an error: source /usr/local/bin/virtualenvwrapper.sh sh.exe: /usr/local/bin/virtualenvwrapper.sh: No such file or directory

I find, where on my drive is virtualenvwrapper.sh and change directory name. On my computer it's /c/Python27/Scripts/virtualenvwrapper.sh. When I again run command

$source /c/Python27/Scripts/virtualenvwrapper.sh

I get the next ERROR message: sh.exe":mktemp:command not found ERROR: virtualenvwrapper could not create a temporary file name

I check my enviroment variable: C:\python27\;C:\python27\scripts\;C:\python27\scripts\virtualenvwrapper.sh\;C:\msys;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin\

I don't know where i made a mistake

2 Answers2

1

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.

khampson
  • 14,700
  • 4
  • 41
  • 43
  • I download mktemp and install it.Then i take from **C:\Program Files(x86)\GnuWin32\bin\mktemp** and place it in the **C:\Program Files (x86)\Git\bin**. –  Jun 30 '14 at 06:47
  • Then i run GitBash and write `1 $ export WORKON_HOME=$HOME/.virtualenvs 2 $ export MSYS_HOME=/c/msys/1.0 3 $ source /c/Python27/Scripts/virtualenvwrapper.sh` And the last line give me again an error: `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. ` –  Jun 30 '14 at 06:48
  • It seems to actually be generating the temp file name, it just can't create it. As a next step I'd recommend looking into the permissions of the Temp folder (and its hierarchy) vs. the user that is running *virtualenvwrapper*. You can perhaps add some debug code to the shell script, and also try to create that temp file in a regular Windows command prompt and then also in GitBash outside of *virtualenvwrapper* and see if it works in any of those cases. – khampson Jun 30 '14 at 23:30
  • 2
    I get the same error. The said file (`tmpXXXX.tmp`) is created though, so the error is unclear to me. I am able to create new files from both the Windows Batch and from GitBash, for example by copying an empty string to an non-existing filename. – Lewistrick Nov 20 '14 at 11:30
1

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.

abm
  • 619
  • 1
  • 7
  • 19