Issue2667

classification
Title: Virtualenv failed to create
Type: crash Severity: major
Components: Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: jeff.allen Nosy List: MightyDash, jeff.allen, stefan.richthofer, zyasoft
Priority: normal Keywords:

Created on 2018-04-12.10:40:30 by MightyDash, last changed 2019-03-07.23:26:05 by jeff.allen.

Messages
msg11892 (view) Author: Jozef Matejička (MightyDash) Date: 2018-04-12.10:40:29
While creating new virtual environment I get error:

Cannot find file C:\prj\tools\jython2.7.1\Include (bad symlink)
msg11893 (view) Author: Jozef Matejička (MightyDash) Date: 2018-04-12.10:42:47
Might be related:
https://github.com/pyenv/pyenv-virtualenv/issues/214
http://bugs.jython.org/issue2329
msg11895 (view) Author: Jozef Matejička (MightyDash) Date: 2018-04-12.13:52:08
C:\prj\src\Python>c:\prj\tools\jython2.7.1\bin\jython.exe -m venv env
Traceback (most recent call last):
  File "C:\prj\tools\jython2.7.1\Lib\runpy.py", line 151, in _run_module_as_main
    mod_name, loader, code, fname = _get_module_details(mod_name)
  File "C:\prj\tools\jython2.7.1\Lib\runpy.py", line 151, in _run_module_as_main
    mod_name, loader, code, fname = _get_module_details(mod_name)
  File "C:\prj\tools\jython2.7.1\Lib\runpy.py", line 104, in _get_module_details
    if loader.is_package(mod_name):
AttributeError: 'org.python.core.JavaImporter' object has no attribute 'is_package'
msg11954 (view) Author: Jeff Allen (jeff.allen) Date: 2018-05-07.16:12:02
I confirm this is a problem, but haven't dug deeper.

PS iss2667> jython -m venv env
C:\Jython\2.7.1\bin\jython.exe: No module named venv

Ok,let's install it ...

PS iss2667> pip -V
pip 9.0.1 from C:\Jython\2.7.1\Lib\site-packages (python 2.7)

PS iss2667> pip install virtualenv
Collecting virtualenv

PS iss2667> virtualenv env
Cannot find file C:\Jython\2.7.1\Include (bad symlink)
New jython executable in C:\Users\Jeff\Documents\Jython\bugs\iss2667\env\bin\jython.exe
Traceback (most recent call last):
  File "C:\Jython\2.7.1\Lib\runpy.py", line 161, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Jython\2.7.1\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Jython\2.7.1\bin\virtualenv.exe\__main__.py", line 9, in <module>
  File "C:\Jython\2.7.1\Lib\site-packages\virtualenv.py", line 703, in main
    create_environment(home_dir,
  File "C:\Jython\2.7.1\Lib\site-packages\virtualenv.py", line 925, in create_environment
    py_executable = os.path.abspath(install_python(
  File "C:\Jython\2.7.1\Lib\site-packages\virtualenv.py", line 1395, in install_python
    os.symlink(py_executable_base, full_pth)
AttributeError: 'module' object has no attribute 'symlink'

The bit about "Cannot find file C:\Jython\2.7.1\Include (bad symlink)" is a red herring. (You can make it go away by creating one.)

As for 
...
  File "C:\Jython\2.7.1\Lib\site-packages\virtualenv.py", line 1395, in install_python
    os.symlink(py_executable_base, full_pth)
AttributeError: 'module' object has no attribute 'symlink'

That's ok, we're on Windows. There isn't supposed to be one:
PS iss2667> python -c "import os; print os.symlink"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'symlink'

I suspect that virtualenv has fallen into the common trap of assuming that if the platform is not Windows it must be POSIX, but here the platform is Java.

We could have done this platform thing differently. At the momemnt the collective judgement of the project is that it is too difficult to change, but I'll see if there's a work-around.
msg11958 (view) Author: Jeff Allen (jeff.allen) Date: 2018-05-07.19:17:11
As I thought, virtualenv is confused by Jython on Windows. Unfortunately, it is not as simple as I thought: virtualenv tests successfully for Jython and makes explicit variations for it in many places. (It is explicitly wrong about the Include directory.)

I can arrange to set virtualenv.is_win = True, but then it just fails looking for msvcrt. Basically, is_jython means Jython on POSIX and is_win means CPython on Windows.
msg12226 (view) Author: Jeff Allen (jeff.allen) Date: 2018-12-31.12:58:01
I think we must conclude that this is a bug in virtualenv that causes it not to support Jython on Windows.
msg12228 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2018-12-31.14:47:45
For the record, JyNI might help here if you set virtualenv.is_win = True:

It enables the msvcrt module for Jython on Windows.
History
Date User Action Args
2019-03-07 23:26:05jeff.allensetstatus: pending -> closed
2018-12-31 14:47:45stefan.richthofersetnosy: + stefan.richthofer
messages: + msg12228
2018-12-31 12:58:01jeff.allensetpriority: normal
status: open -> pending
resolution: invalid
messages: + msg12226
2018-05-07 19:17:11jeff.allensetnosy: + zyasoft
messages: + msg11958
2018-05-07 16:12:03jeff.allensetassignee: jeff.allen
messages: + msg11954
nosy: + jeff.allen
2018-04-12 13:52:08MightyDashsetmessages: + msg11895
2018-04-12 10:42:48MightyDashsetmessages: + msg11893
2018-04-12 10:40:30MightyDashcreate