question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ipython fails to launch

See original GitHub issue

I am completely stuck with a persistant error that stops ipython from launching for the past few days. It initially started when I upgraded ipython to 8.0, but now occurs for previous ipython versions as well.

Background: I am running python on Windows 10 using the 64-bit build downloaded from https://www.python.org/. I am using pip and running python and ipython from the mobaxterm terminal. I had been able to run ipython for the past couple of years this way without issue.

The error: Unfortunately, after a recent pip package update, ipython now fails to launch and returns the following message:

  03/02/2022   21:02.44   /home/mobaxterm  ipython
Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.1 -- An enhanced Interactive Python. Type '?' for help.
Traceback (most recent call last):
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\Scripts\ipython.exe\__main__.py", line 7, in <module>
    sys.exit(start_ipython())
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\site-packages\IPython\__init__.py", line 123, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\config\application.py", line 845, in launch_instance
    app.initialize(argv)
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\site-packages\traitlets\config\application.py", line 88, in inner
    return method(app, *args, **kwargs)
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\site-packages\IPython\terminal\ipapp.py", line 283, in initialize
    self.init_code()
  File "C:\Users\Andrew Friedman\AppData\Local\Programs\Python\Python39\lib\site-packages\IPython\core\shellapp.py", line 315, in init_code
    sys.stderr.flush()
AttributeError: 'NoneType' object has no attribute 'flush'

The distressing thing is that I’m unable to get back to the previous ipython functionality, so it is now completely unusable. I have removed and reinstalled python and all of my pip packages several times, and removed the .ipython/ directory, but I continue to get the same error. It persists even when I downgrade python or ipython back to earlier versions that used to work fine (7.31 or 7.22).

Many thanks in advance for any suggestions.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
charliemancommented, Feb 27, 2022

Hello, I was looking at this again and found that running ipython like this: python -m IPython works fine. It’s only when using the ipython.exe executable (located in C:\Python310\Scripts\ipython.exe) from bash that sys.stderr is None.

So it seems the problem does not come from ipython but the shim .exe files themselves. I did the same check using pip.exe and python -m pip and surely sys.stderr was also set to None when running the former.

I don’t know how these shims get generated, running xxd on them I can see at the end of the file there’s the actual python script they run, for IPython it’s this:

import re
import sys
from IPython import start_ipython
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

So the .exe somehow clears sys.stderr but only when run from windows bash. My new workaround is to alias ipython="python -m IPython" in my .bashrc

1reaction
MrMinocommented, May 30, 2022

I’m going to close this as non-ipython issue. Anyone encountering this problem is invited to try and install ipython with the version of pip that ships with distlib==0.3.3. Remember that pip vendors its dependencies, so the version of distlib in your pip freeze does not matter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What to do when things go wrong - The Jupyter Notebook
Jupyter fails to start · Have you installed it? ;-) · If you're using a menu shortcut or Anaconda launcher to start it,...
Read more >
can't run ipython on cmd - Stack Overflow
To find that out, I ran pip show ipython and it showed me some info, including the path of the module (for me:...
Read more >
Ipython fails to open - Discussions on Python.org
I am doing basics in python programming and I try to install ipython to my laptop. I have a windows 10 to work...
Read more >
Launching Jupyter ALWAYS results in Kernel Failure - Notebook
To help get to the bottom of this, run jupyter kernelspec list , identify the location relative to the kernel you're currently having...
Read more >
Quickstart — IPython 2.4.2-maint documentation
To run IPython's test suite, use the iptest command: ... We will not consider completion/history problems to be bugs for IPython if you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found