Python - I can't use function display in pycharm - python

I can use the function display() to see my excel data just fine on google colabs or jupyter, but can't use it on pycharm and have to use print instead. Why is that?

Display is a module which is a part of IPython. Jupyter notebooks run the IPython kernel to execute code.
Pycharm on the other hand is just an IDE, which is completely unrelated to IPython.
In other words, the display() function isn't part of the python STL, it's just something that IPython provides, which is why you can use this function in Jupyter Notebooks.

Related

quickly try line of code and work with variables in visual studio code

I am more used to Spyder and very new in vsc. In Spyder you have a python console where you can quickly try a codesnipped like:
print(len(a))
without having to run the entire code.
Is that also possible in vsc? I have not seen anything.
In addition, I can only see the variables in the debug mode. In Spyder I have all variables after one run at hand and can try and experiment on the fly with them. Is there another Variable-viewer plugin or how could that be enabled?
You can use this extensions of python. It has a Jupyter Notebook feature that comes with a variable explorer. It is recommended to also add the Jupyter extension as well (they work together just fine), you can find it here.
You can read this documentary about how to use Jupyter with visual studio code, you can see that it shows how to display the variables the way you wanted.

python jupyter coding confusion

I got some python course on udemy but whole course is in jupyter,my question is what is difference bewteen .py coding and .ipynb?why course is in jupyer but everyone on youtube coding in VsCode/Pycharm/Sublime without jupyer notebook integration
for example in jupyter
a = 20
a
and you will get result but in VsCode nothing happens you must Create New Jupyter Notebook integration for that.
It is the same result you will get but with different coding(.py/.ipynb) or i am missing something?
This is the difference between using interactive mode and script mode.
Jupyter is an IDE (Interactive Development Environment). One of the features is that when you enter an expression, the interpreter prints that value. A formal Python script doesn't display unless you explicitly tell it to do so with the print method. To get your value displayed, use
a = 20
print(a)
Thank you for response,so basically everything you can do in script mode you can do in interactive mode?(also big project)

"New Console for notebook" for jupyter notebook in visual studio code

Jupyter lab has this feature where I can have a ipython console for every notebook I have opened. Whenever I run a cell inside this notebook, the console will have all the variables defined and modules imported corresponding to notebook. In addition, we can run extra commands and helps in debugging at times. Is there a similar feature in VS code? I really like it and would like to move completely to vs code. Python interactive command line in vscode is the closest to this that I found. However, it is not attached to the notebook and I have to run all the code inside the notebook which is a bit tedious.
I believe this would work Connecting a terminal to an existing kernel
However, you're likely looking for a way to do this within VS code. You might be able to do this by running %connect_info in a cell, starting a terminal, and then running the appropriate jupyter command.
Something like so:
jupyter console --existing kernel-2c0993da-95c7-435a-9140-118c10d33e1a.json
If you're refering to .py files you can do that the same way you would in pycharm.
First, you need to put a breakpoint in the code:
Them you run the code with the debugger:
Then, when the code reaches the breakpoint, you will be able to play with the variables, like the Jupyter terminal:
I also like to have a JupyterLab-style console open that is connected to a notebook. This is my workaround in order to achieve this in Visual Studio Code (at least it works when my kernel is a remote Jupyter session).
Suppose your notebook is called hello.ipynb.
Create a dummy file called hello.py.
Open hello.py, right-click in the code window and choose Run Current File in Interactive Window. This opens the JupyterLab-style console.
Change the kernel for the interactive window to the same kernel that the notebook hello.ipynb is using.
(Optional) Close the hello.py tab since it is not needed.
Now I have an interactive window sharing everything with the notebook.

Attach external system terminal into Spyder

I have been running into a trouble whereby Spyder IPython console is not producing Matplotlib figures as desired. I thought initially that there is something wrong in my code since jupyter notebook gives me the same wrong figures. However, when running the script in Spyder using external terminal the figures are produced as desired. Also, when I run the code in VSC the correct figures are displayed.
So the only option I am left with in Spyder is to use the external terminal to execute the code. However, it is quite a pain every time to run some codes and then manually close the terminal.
I would like to know if there is a way to permanently attach the external terminal inside Spyder? I hate the IPython console when it comes to plotting matplotlib figures!!
(Spyder maintainer here) Sorry but there's no way to dock an external Python terminal inside Spyder.

Synchronize .ipynb and .py to use ipython notebook and eclipse at the same time

I started programming some scripts with ipython notebook but now the project is becoming to big for a notebook. Nevertheless I love to execute my stuff in an ipython notebook (load de data only once, online figures...).
What I would want is to program everything with eclipse but executing it in ipython. I know I can save the notebooks as .py by adding the --script option at the beginning. But now I want to automatically make the process the other way around. I mean, I want my ipython notebook to reload de code I modify with Eclipse.
Is it possible?
Should I make a program that makes it using the converter?
Thanks!!
I found the solution for manually updating the functions without rerunning the whole .ipynb file. However, I do not know how to make it automated. Here is the solution:
Synchronizing code between jupyter/iPython notebook script and class methods
To cut it short you need to put reload function from importlib module in the cell of interest:
import babs_visualizations
from importlib import reload
reload(babs_visualizations)
Just a little addition: make sure that you are addressing the function in the form of moldule.function. If you previously imported function by from module import function and then reloaded the module the function will not be reloaded. You can put the function inside the notebook cell and rerun it to see, how the changes in the module affected the function output in the notebook.
I hope this was helpful for someone.

Categories

Resources