Not able to get a normal jupyter notebook file - python

I'm starting a python project and when I'm opening a jupyter notebook in the directory I'm getting the following file. Normally there are other tabs such as kernel. Additionally I'm not able to run code using control + shift.

Jupyter notebooks are the files with extension .ipynb not with the extension .py which you are opening right now (main.py).
Look for a file with .ipynb extension and open it, it will run fine.

Related

Convert .py to .ipynb file in pycharm

As Jupyter Notebook integration is available in PyCharm professional, is there a GUI option to convert a .py to a .ipynb file?
I tried to edit the file extension, e.g. from test.py to test.ipynb, but then I can't open the .ipynb file.
Simplest way I found without installing extra dependencies is:
Create a new notebook: File > New > Jupyter notebook
Copy and paste the Python code into it
Then you can add #%% markers to separate the cells.
If all you want is just to run your code cell by cell directly on Pycharm's console, you don't need to convert it from .py to .ipynb.
Just activate View > Scientific Mode and add #%% markers to separate the cells directly in your .py file. Now you can execute it by using the green arrows on the left side of your code.
Tested on Pycharm professional 2020.3.2
Try using
pip install ipynb-py-convert
https://medium.com/#researchplex/the-easiest-way-to-convert-jupyter-ipynb-to-python-py-912e39f16917

How to open .ipynb file in Spyder?

without using iSpyder DOS shell commands, how can an .ipynb (Jupyter Notebook) be opened directly into Spyder on Windows? Even the online Jupyter Notebook site prompts for a relative directory path where the file is stored.
Why isn't there something that just loads the Notebook how it's supposed to look without typing a bunch of directory commands,
and why does Spyder's RUN button become greyed out when it loads the .ipynb file?
I have no idea what the .ipynb file format is compared to regular .py files
Opening lines of the .ipynb when loaded in Spyder are:
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
This does not look like python code whatsoever
You may check out https://github.com/spyder-ide/spyder-notebook
Once you install this, you can open native .ipynb files in spyder
From the website:
Spyder plugin to use Jupyter notebooks inside Spyder. Currently it
supports basic functionality such as creating new notebooks, opening
any notebook in your filesystem and saving notebooks at any location.
You can also use Spyder's file switcher to easily switch between
notebooks and open an IPython console connected to the kernel of a
notebook to inspect its variables in the Variable Explorer.
The jupyter notebook plugin currently works with Spyder 4.2.5 version and will not work with Spyder 5.X versions.
If you are using Spyder-5.x and therefore cannot use the Spyder-notebook plugin (see the other answers), an alternative is to export the .ipynb from Jupyter as an executable .py script first, then open the .py script in Spyder.
Jupyter->Files->Save and Export Notebook as->Executable script
The .py script produced preserves the ipython cells, using the
# In[<cell name or number>]:
syntax, for dividing the code into cells.
In Spyder, you can then right-click on the cell, and select Run cell to execute it in the Spyder console.
Beware, that all the cells (Code, Markdown, and Raw) are saved in the .py script. You may need to add '''block quotes''' around your Markdown and Raw cells, to prevent SyntaxErrors when running the .py script file.

What is the difference between a .py file and .ipynb file?

I have read about .py and .ipy, also the difference between python, ipython and notebook.
But the question is: what is the real difference between .py and .ipynb file?
Is .ipynb file just more convenient to be run on jupyter notebook, or anything more? I am wondering because I am thinking about which format to be used for publishing on GitHub.
Thanks
.py is a regular python file. It's plain text and contains just your code.
.ipynb is a python notebook and it contains the notebook code, the execution results and other internal settings in a specific format. You can just run .ipynb on the jupyter environment.
Better way to understand the difference: open each file using a regular text editor like notepad (on Windows) or gedit (on Linux).
Save on git the .ipynb if you want to show the results of your script for didatic purposes, for example. But if you are going to run your code on a server, just save the .py
Adding #Josir answer, the below information is very useful for open .ipynb file using PyCharm.
Create a new Python project in Pycharm
Specify a virtual environment, and install the jupyter package(pip install jupyterlab).
Run the server using the jupyter-lab command.
Browser will open the jupyter notebook like below, there you can execute the .ipynp file.
Here is documentation https://jupyterlab.readthedocs.io/en/latest/
py means PYthon
ipynb means Interactive PYthon NoteBook - which is now known as Jupyter notebook.
The latter one is merely a Python script with descriptive contents - you describe what your data is doing by means of Python script and some funny texts. That's pretty much it - and also, you need a specific editor e.g. PyCharm or Google Collab to open and run it.
I think the answer here might help you: https://stackoverflow.com/a/32029027/11924650
.ipy indicates that it's an IPython script. The only difference between IPython scripts and normal Python scripts is that IPython scripts can use IPython magics, e.g. %timeit, and run system commands as !echo Hi.

what's the problem to my file extentions (.ipynb , .py)

I changed the extension of the file after working on the jupyter notebook.
(.ipynb -> .py)
After that I got a problem.
I can not go back to try to go back to the .ipynb with strange files.
How can someone help me? :j
If you mean changing just the extension then it wont..it's like saving the features of ipynb notebook to .py file. Instead you can download the IPYNB as PY file on Jupyter notebook itself..

Downloaded .py file not working in Jupyter

I'm new to programming and now taking the course MIT 6.0001. On problem set 2, they set a .py file, accompanied with a .txt file.
I ran .py file in Spyder with no difficulties (.txt file embedded just fine).
But when I run .py file in Jupyter, things won't run (as in screenshot).
I want to use Jupyter because it's much clearer than Spyder, and can give headers to cells to keep myself on track. Please help me to run things in Jupyter.
Here are link to the problem set (ZIP file)
File not running in Jupyter
Use
%load filename.py
to import the text of your python file into a cell in a Jupyter notebook and then save that notebook.
Jupyter isn't built to run/edit .py files, it's built to run/edit jupyter notebooks (ipython notebooks) (.ipynb)

Categories