I often use jupyter for classes, and use the commmand python -m notebook to open the notebook. The tab that opens up shows an error, and then I have to copy one of the links in the terminal window instead. Is there a way or a command that I can use so that one of those links automatically opens up?
NOTE: It opens the file location (first address in the picture) and fails, and I use the links below to open jupyter. I want the terminal to open the links directly if possible to save time.
This is the error that I get.
jupyter notebook notebook.ipynb
Taken from this documentation.
It shouldn't matter whether you install it using conda or pip.
Or you can just type jupyter notebook which should open up a your file directory in the browser and let you navigate to the notebook file you want to open.
Edit: For this error, it really is hard without knowing the full context of the commands you are running, the directory you are calling from, and where this file you want to open is located. Make sure you are in the folder that contains your notebook file. If not, you should specify the entire path to the notebook file. Finally, does the command jupyter notebook by itself work?
Related
I've been searching for a way to open jupyter notebooks by double clicking on .ipynb files in Windows explorer, and I've installed nbopen since visiting this stackoverflow answer.
Jupyter notebooks run fine on my computer, and I can open a server if I navigate to the correct folder in anaconda prompt and type for instance jupyter notebook or nbopen file.ipynb.
However, when double clicking on .ipynb files (or "open with" nbopen.exe) I get the error messages displayed in the screenshot below. Apologies for the lack of a text version - the window disappears very quickly and I've only captured this by means of well-timed screenshot taking (incidentally, any tips on how to capture short-lived error messages like this in future would be appreciated). After the window has disappeared, nothing further happens
To try to resolve the error I have reinstalled nbopen but no success. I have also tried opening the .ipynb files with jupyter-notebook.exe, which duplicates this error message after from notebook import notebookapp.
The default python version (i.e. the first result for python --version) on my PC is Python 3.8.5.
Every time when I try to run a file in the JupiterLab console I get the following message:
ERROR:root:File 'thing.py' not found.
In this case, my file is called thing.py and I try to run it with the trivial run thing.py command in the console. The code is running and it gives me correct results when executed in the console, but I wanted to have it saved, so I put it in a JupiterLab text file and changed the extension to .py instead of .txt. But I get the aforementioned message regardless of which file I try to run. I am new to JupiterLab and admit that I might have missed something important. Every help is much appreciated.
If you're running Jupyterlab you should be able:
to create a new file & paste in your commands
Rename that file to "thing.py"
And then open a console in the same Jupyterlab instance and run that file. Notice that you can see "thing.py" in the file explorer on the left:
Alternatively, you can use the %load magic command in a notebook to dynamically load the code into a notebook's cell.
You might want to understand exactly what a Jupyter Lab file is, and what a Jupyter Lab file is not. The Jupyter Notebooks have the extension, .ipynb.
So anyway, the Jupyter Notebooks are not saved or formatted with python extensions. There are no Jupyter Notebooks or Jupyter Labs ending with the .py extension. That means Jupyter will not recognize an extension having .py, or .txt or .R or etc.... Jupyter opens, reads, and saves files having the .ipynb extension.
Jupyter Notebooks are an open document format based on JSON.
Jupyter can export in a number of different formats. Under the File tab, is the Export feature. The last time I looked there were about 20 different export formats. But there isn't a python or .py export format. A Jupyter file can also be Downloaded. Also under the File tab is the Download feature. This will download a standard text formatted JSON file. JSON files are mostly unreadable unless you've spent years coding JSON.
So there's not much purpose in downloading the Jupyter file unless you are working on a remote server and cannot save your work at that site. And it makes much more sense to save and copy the Jupyter file in its native Jupyter format - that means having the extension, .ipynb . Then just open and use that file on another PC.
Hopefully this should clarify why Jupyter won't open any .py or .txt files.
I've been trying to figure out how I can open a .ipynb file on double-click on a Mac, so the file opens with Anaconda and then automatically opens Jupyter Notebook with the file contents.
I have tried creating an application through Automator that opens with a jupyter_lab command, but the issue is that Jupyter lives in Anaconda, so this method is not working. See these articles for my steps: https://samedwardes.com/2020-01-31-open-ipynb-with-double-click/ and Open an ipython notebook via double-click on osx
I have also tried installing nbopen with the following:
python3 -m pip install nbopen
This works, and then I can run nbopen file.ipynb through the terminal, but I want to be able to bypass this step and do it while in file explorer, physically looking at the file instead.
I have ran the recommended command for osx to integrate it with file manager ./osx-install.sh but I just get zsh no such file or directory and can't really find any help with figuring out why this is pushing back an error.
Any suggestions?
I have this "convenience issue" as well, and didn't go for the nbopen route, but instead, I just made a batch script (I named it jupyter-notebook.bat) that calls certain conda functions, and pretty much initiates things like how double clicking works. In the script, I just have this:
call "C:\Users\XYZ\Anaconda3\Scripts\activate.bat"
call conda activate myEnvironment
call python C:\Users\XYZ\Anaconda3\Scripts\jupyter-notebook-script.py %1
Lastly you just need to configure that every .ipynb opens up using your jupyter-notebook.bat script.
For consistency, I placed the script in my Anaconda folder. And if you also have nb_conda_kernels installed in your base environment, you'd have access to the other environment you've created as well from there.
My Jupyter/IPython notebooks reside in various directories all over my file system. I don't enjoy navigating hierarchies of directories in the Jupyter notebook browser every time I have to open a notebook. In absence of the (still) missing feature allowing to bookmark directories within Jupyter, I want to explore if I can open a notebook from the command line such that it is opened by the Jupyter instance that is already running. I don't know how to do this....
Option 1: Run multiple jupyter notebook servers from your project directory root(s). This avoids navigating deeply nested structures using the browser ui. I often run many notebook servers simultaneously without issue.
$ cd path/to/project/; jupyter notebook;
Option 2: If you know the path you could use webbrowser module
$ python -m webbrowser http://localhost:port/path/to/notebook/notebook-name.ipynb
Of course you could alias frequently accessed notebooks to something nice as well.
Related posts: Open an ipython notebook via double-click on osx
How can I open Ipython notebook from double click? I always cd to the directory of the notebook, then type ipython notebook in the browser and then open it in the browser. This steps is very inconvenient.
In windows, I remembered that I can change the directory in the browser, but in linux there is no way to explore to other directory via browser, if I want to open a new book in another directory, I have to restart another kernel as above, which annoys me.
Is there any simple and verified way to do this?
You can use a project like nbopen that handle that and will open the browser on the right notebook + start an IPython server if one is not yet running.
pip install nbopen.
open Automator, create new Application
Drag'n drop Run Shell Script
Change Pass input to as arguments
Copy/paste this script:
variable="'$1'"
the_script='tell application "terminal" to do script "nbopen '
osascript -e "${the_script}${variable}\""
Save the new application to Applications directory as nb_open
Right click any ipynb file and select "Open with > Other" and select the nb_open in the Applications folder. Don't forget to check "Always Open With".
Select an ipynb file, get info (command + i) > Open With (select nb_open if not selected already) > Click Change All.... Done.
To "promote" Yogesh's helpful comment to a fully self-contained answer:
Windows 10
In a CMD or PowerShell window with administrative rights (e.g. launched quickly with Win+X, then A), run:
pip install nbopen
python -m nbopen.install_win
Profit!
Double-click on *.ipynb files now starts a new server or reuses an existing instance.
One way to open a Jupyter notebook directly by double-clicking on the file is to associate the .ipynb file extension with the jupyter-notebook command. Here's how to do it on a Windows system:
Right-click on the Jupyter notebook file that you want to open.
Select "Open with" and then choose "Choose another app".
Select "More apps" and then scroll down to the bottom and choose "Look for another app on this PC".
Navigate to the directory where the jupyter-notebook.exe file is located (usually in the Scripts subdirectory of your Python installation), and select it.
Check the box next to "Always use this app to open .ipynb files" and then click on "OK".
Now, when you double-click on an IPython notebook file, it should open directly in the Jupyter notebook.
On a Mac or Linux system, you can set the default application for .ipynb files by using the xdg-mime command. First, determine the full path to the jupyter-notebook executable:
which jupyter-notebook
This will return the path to the executable. Then, use the xdg-mime command to set the default application for .ipynb files:
xdg-mime default jupyter-notebook.desktop application/x-ipynb+json
Replace jupyter-notebook.desktop with the path to the jupyter-notebook executable that you determined earlier. Now, when you double-click on an IPython notebook file, it should open directly in the Jupyter notebook.