Repository: pypa/virtualenv

Issue:
virtualenv 1.8.4 broken on cygwin
On cygwin, virtualenv 1.8.2 works fine, but 1.8.4 fails as follows:

  $ virtualenv xyzq
New python executable in xyzq/bin/python2.6
Also creating executable in xyzq/bin/python.exe
Traceback (most recent call last):
  File "/usr/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==1.8.4', 'console_scripts', 'virtualenv')()
  File "/usr/lib/python2.6/site-packages/virtualenv.py", line 964, in main
    never_download=options.never_download)
  File "/usr/lib/python2.6/site-packages/virtualenv.py", line 1065, in create_environment
    site_packages=site_packages, clear=clear))
  File "/usr/lib/python2.6/site-packages/virtualenv.py", line 1506, in install_python
    raise e
OSError: [Errno 2] No such file or directory

If you edit /usr/lib/python2.6/site-packages/virtualenv-1.8.4-py2.6.egg/virtualenv.py
to log what file is being accessed, you see that it's trying to run xyzq/bin/python2.6.exe,
which does not yet exist; xyzq/bin contains just three symlinks (python, python2, and python2.6)
all pointing to python2.6.exe, but no real files.

Workaround:
$ pip uninstall virtualenv
$ pip install virtualenv==1.8.2



Discussion:
Hmm so this is probably due to pull #341 

@pfmoore any thoughts on the cygwin support here - should we just not symlink on is_cygwin too?

Sorry, I've no idea on cygwin, I don't use it myself. I'll try to get a chance to dig around and see if I can follow what's going on with the code at some point.

+1, thanks for the workaround @dankegel.

This is effecting me too :cry: 

Works under current develop branch.
Tested under cygwin 1.7.17-1 running on Windows 8.

EDIT: Odd, now its broken again... I'll have to look into this further...

Ok. I think I've found the issue, in the code that adds .exe to python under cygwin

``` python
if is_cygwin and os.path.exists(executable + '.exe'):
            # Cygwin misreports sys.executable sometimes
            executable += '.exe'
            py_executable += '.exe'
            logger.info('Executable actually exists in %s' % executable)
```

I'm not really sure I see a reason for this code to exist, because as far as I know, cygwin treats the .exe extension as optional. Including it or not will point to the same code. However, when it gets down to the code that adds symlinks, it adds a symlink from python2.6 to python2.6.exe, which cygwin promptly overwrites the python2.6.exe with.  So you end up with 3 symlinks, and no python executable. This can be fixed by removing the .exe from the py_executable, as it will then trigger the already existing check for this case. 

I'll submit a pull request as soon as I figure out how to run the tests, but it really just amounts to the removal of those 5 lines above.


Resolving patch:
diff --git a/virtualenv.py b/virtualenv.py
--- a/virtualenv.py
+++ b/virtualenv.py
@@ -1352,11 +1352,6 @@ def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear):
     if sys.executable != py_executable:
         ## FIXME: could I just hard link?
         executable = sys.executable
-        if is_cygwin and os.path.exists(executable + '.exe'):
-            # Cygwin misreports sys.executable sometimes
-            executable += '.exe'
-            py_executable += '.exe'
-            logger.info('Executable actually exists in %s' % executable)
         shutil.copyfile(executable, py_executable)
         make_exe(py_executable)
         if is_win or is_cygwin:


Test patch: