Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPython REPL will not start when startup script specified #976

Closed
oglohon opened this issue Nov 6, 2015 · 7 comments
Closed

IPython REPL will not start when startup script specified #976

oglohon opened this issue Nov 6, 2015 · 7 comments
Assignees
Labels

Comments

@oglohon
Copy link

oglohon commented Nov 6, 2015

I am new to Python and Visual Studio and having issues getting IPython to work (I need to be able interactively plot data using matplotlib).

I've gone into Python Tools\Interactive Windows\Interactive Mode and set it to IPython. Once I start typing in the REPL I get the following error:

Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.2\visualstudio_py_repl.py", line 1370, in
_run_repl()
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.2\visualstudio_py_repl.py", line 1366, in _run_repl
BACKEND.execution_loop()
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.2\visualstudio_ipython_repl.py", line 308, in execution_loop
self.execute_file_as_main(self.launch_file, None)
File "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.2\visualstudio_ipython_repl.py", line 291, in execute_file_as_main
contents = f.read().replace("\r\n", "\n")
TypeError: expected bytes, bytearray or buffer compatible object
The Python REPL process has exited

I'm using Visual Studio Pro 2013 with PTVS 2.2
Python 3.4
IPtython 3.0

Any insight would be appreciated.

@zooba
Copy link
Member

zooba commented Nov 6, 2015

Wow, this bug has been here for years... thanks for finding it!

Our next release (coming very soon) isn't going to have the fix, but once I've written one up you'll be able to apply it manually to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.2\visualstudio_ipython_repl.py.

@zooba zooba self-assigned this Nov 6, 2015
@zooba
Copy link
Member

zooba commented Nov 6, 2015

Just to confirm - in Interactive Options, what value (or maybe just spaces?) do you have for Startup Script? The error you're hitting is for when a startup script is specified, which is apparently not a very common thing for people to do, but I get a different error when I put a Python file there.

@oglohon
Copy link
Author

oglohon commented Nov 7, 2015

I do use a startup script (something I'm used to coming from MATLAB). Maybe I shouldn't? This is what was in there.

C:\Users\vu062605\Documents\Visual Studio 2013\Projects\TunnelTools\TunnelTools\setupinteractive.py

I removed the startup script and sure enough, the REPL seems to work in IPython mode. I was hoping switching to IPython mode would fix my actual issue (which is wanting to be able to make plots from matplotlib without each plot window hanging up and "Not Responding"). But that's a question for a different thread I think.

@zooba
Copy link
Member

zooba commented Nov 7, 2015

Not using the startup script is a workaround, as the bug is in our code that loads the startup script. I'd rather fix the bug than tell you not to use it though.

The matplotlib issue should be helped by changing to IPython mode. The main difference is that matplotlib will use a different backend:

In [2]: matplotlib.get_backend()
Out[2]: 'module://IPython.kernel.zmq.pylab.backend_inline'

vs normal mode:

>>> matplotlib.get_backend()
'TkAgg'

The TkAgg backend is the one that pops up a separate window. You can specify the backend using matplotlib.use(), but I don't think we'll display plots properly unless you're in IPython mode.

zooba added a commit to zooba/PTVS that referenced this issue Nov 7, 2015
Adds missing str->bytes conversion for Python 3.x.
@zooba
Copy link
Member

zooba commented Nov 7, 2015

So if you click through to the commit linked above, you'll see the changes you can make to your own install to get the fix right away.

@zooba zooba changed the title iPython REPL will not start IPython REPL will not start when startup script specified Nov 7, 2015
@oglohon
Copy link
Author

oglohon commented Nov 7, 2015

Thanks! That fixed the REPL issue. I still can't get matplotlib to create a window though.

In [1]: plt.get_backend()
Out[1]: 'Qt4Agg'

In [2]: plt.ion()

In [3]: plt.plot([1, 1])
Out[3]: [<matplotlib.lines.Line2D at 0x8142b50>]

matplotlib error

I get the same backend in standard mode

>>> plt.get_backend()
'Qt4Agg'

Should that be the case?

@oglohon
Copy link
Author

oglohon commented Nov 7, 2015

I figured out if I set Interactive Mode to IPython w/o Pylab, then enter

>>> %matplotlib

as the first thing I do (before the REPL has started), everything works as expected. I'm not sure what that does exactly but I'm running now.

Thanks again for your help and looking at this. I was beginning to start looking at other IDEs.

zooba added a commit that referenced this issue Nov 12, 2015
Fixes #976 IPython REPL will not start
@zooba zooba closed this as completed in 729f5fa Nov 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants