Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open an interactive Python prompt in Google Colab?

How does one open an interactive Python console/shell/prompt within Google Colab? Is it possible? An iPython prompt would be ideal but a regular prompt would suffice.

Also, it would be significantly more useful if the console's interpreter shared access to the variables/state with the Colab notebook's kernel.

like image 766
Jon Deaton Avatar asked May 18 '26 01:05

Jon Deaton


1 Answers

!jupyter console --existing appears to hang with no output because it is waiting to acquire the GIL in the same process as the notebook's runtime that is executing the ! magic, which isn't going to give it up until the ! is done. For the same reason I don't think it's going to be easy to get a subprocess invocation to share state with the notebook's runtime. Obvs. you could program your own input() + eval() in a loop to simulate a py prompt that shared the env with your notebook.

like image 72
Ami F Avatar answered May 20 '26 15:05

Ami F



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!