ipython / ipython

Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
https://ipython.readthedocs.org
BSD 3-Clause "New" or "Revised" License
16.28k stars 4.43k forks source link

IPython fails to run on virtualenv when called from git-bash in MinTTY (Windows 10) #11085

Open tsela opened 6 years ago

tsela commented 6 years ago

I do my Python development on a Windows 10 machine with Git installed, doing all my command line work using Git Bash, either stand-alone (running in MinTTY) or within Visual Studio Code. I also have virtualenvwrapper installed to handle virtual environments easily.

My problem is that when I have IPython installed in a virtualenv, it will run fine if I call it from Bash in the Terminal window of VSCode, but it will fail when I call it from Bash in MinTTY.

Here is the output when I run IPython from VSCode:

(gc_lubes_labels)
Christophe.Grandsire@ASS-L-91701 MINGW64 ~/Cases/Data/GC Lubes Label Control
$ ipython
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.3.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]:

As you can see, it works properly. But if I run it from Bash in MinTTY (for instance starting Git Bash from the Windows menu or the context menu of a directory), here is what I get:

(gc_lubes_labels)
Christophe.Grandsire@ASS-L-91701 MINGW64 ~/Cases/Data/GC Lubes Label Control
$ ipython
Traceback (most recent call last):
  File "c:\program files\python36\Lib\runpy.py", line 193, in _run_module_as_mai
n
    "__main__", mod_spec)
  File "c:\program files\python36\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Christophe.Grandsire\.virtualenvs\gc_lubes_labels\Scripts\ipyth
on.exe\__main__.py", line 9, in <module>
    sys.exit(start_ipython())
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\IPython\__init__.py", line 125, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\traitlets\config\application.py", line 657, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-113>", line 2, in initialize
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\traitlets\config\application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\IPython\terminal\ipapp.py", line 317, in initialize
    self.init_shell()
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\IPython\terminal\ipapp.py", line 333, in init_shell
    ipython_dir=self.ipython_dir, user_ns=self.user_ns)
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\traitlets\config\configurable.py", line 412, in instance
    inst = cls(*args, **kwargs)
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\IPython\terminal\interactiveshell.py", line 430, in __init__
    super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\IPython\core\interactiveshell.py", line 483, in __init__
    self.init_virtualenv()
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\site-pack
ages\IPython\core\interactiveshell.py", line 740, in init_virtualenv
    if p_exe_up2 and os.path.samefile(p_exe_up2, p_venv):
  File "c:\users\christophe.grandsire\.virtualenvs\gc_lubes_labels\lib\genericpa
th.py", line 97, in samefile
    s2 = os.stat(f2)
FileNotFoundError: [WinError 3] The system cannot find the path specified: '\\c\
\users\\christophe.grandsire\\.virtualenvs\\gc_lubes_labels'

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True

(gc_lubes_labels)
Christophe.Grandsire@ASS-L-91701 MINGW64 ~/Cases/Data/GC Lubes Label Control
$

The output of IPython.sys_info() on my machine for that particular virtualenv is:

{'commit_hash': 'e1aef1899',
 'commit_source': 'installation',
 'default_encoding': 'utf-8',
 'ipython_path': 'c:\\users\\christophe.grandsire\\.virtualenvs\\gc_lubes_labels\\lib\\site-packages\\IPython',
 'ipython_version': '6.3.1',
 'os_name': 'nt',
 'platform': 'Windows-10-10.0.14393-SP0',
 'sys_executable': 'c:\\users\\christophe.grandsire\\.virtualenvs\\gc_lubes_labels\\scripts\\python.exe',
 'sys_platform': 'win32',
 'sys_version': '3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 '
                'bit (AMD64)]'}

Notice that in another virtualenv, IPython does run fine in Bash in MinTTY, although I do get a warning when I run it:

(records_management)
Christophe.Grandsire@ASS-L-91701 MINGW64 ~/Cases/Code/Records Management (prep/nam-process/chris)
$ ipython
c:\users\christophe.grandsire\.virtualenvs\records_management\lib\site-packages\
IPython\core\interactiveshell.py:728: UserWarning: Attempting to work in a virtu
alenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]

Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]:

The only difference between the two environments is the IPython version: 6.3.1 in the environment where IPython completely fails to run, 6.2.1 where it runs but displays the virtualenv warning.

Any idea what's going on? I can run IPython fine as long as I stay within VSCode, but I'd like it to work in a simple Git Bash window as well.

Thanks in advance for your help.

tsela commented 6 years ago

It's been a month and a half and no one's even looked at this issue. Could someone please have a look? It's a really annoying bug that impedes my work quite a lot and it's still present in version 6.4.0.

tsela commented 6 years ago

The issue is still present in IPython 6.5.0. This really is making my work difficult. Could someone at least have the decency to acknowledge the issue?

tsela commented 6 years ago

I've now also established that the error also crops up when using ConEmu rather than MinTTY, so it happens for multiple terminal emulators, but strangely not when using the integrated terminal in VSCode. Please advise.

Carreau commented 6 years ago

Apologies, most of the work here is volunteer work, and we do not have a lot of contributors/dev with windows machine and windows experience. So most of the time issues are fixed if someone is willing to put some elbow grease and provide a patch.

If really this is blocking and you need payed support, you can talk to companies like Anaconda, which do have developers with the right resources, and generally upstream the patches once they have a fix.

It seem like in MinTTY VIRTUAL_ENV point to a non existing dir, that mean we'll need to figure out why, and what's the good behavior.

Maybe just catch FileNotFoundError and exit the function without doing anything ? But that may be just a footgun.

If you are unfamiliar with github/pull-request but can even just modify your local copy in a way that works and tell us how, that would be usefull.

Thanks.