Error loading Jupyter Notebook from a child directory - python

Since I have updated to macOS Big Sur (I have managed to fix all of the Python issues that Big Sur created on my computer. This article is helpful for that), I've been unable to open the Jupyter Notebooks in any of the child directories of where I start my Jupyter Notebook.
I can however open notebooks in the same directory as where I had started my Jupyter Notebook instance.
Here is a screenshot of the error message:
Here also is the error message I get in the terminal when trying to open a new notebook in a child directory:
[W 20:18:51.458 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20210723201825 (::1) 2.560000ms referer=http://localhost:8888/notebooks/0001_analysis/Untitled2.ipynb?kernel_name=python3
I use pyenv and poetry to manage my python environment and packages. I have the local version of python set to Python 3.8.2.
Here are my poetry dependencies in my pyproject.toml:
[tool.poetry.dependencies]
python = "^3.8
[tool.poetry.dev-dependencies]
pandas = "^1.3.0"
scikit-learn = "^0.24.2"
jupyter = "^1.0.0"
seaborn = "^0.11.1"
ipykernel = "^6.0.1"
Would be great to fix this, as it is inconvenient having to create new notebook instances when I need to open notebooks in different child directories of my project.

This may be system integrity protection, though I've seen it in Catalina before, did you leapfrog a version ?
If you are starting Jupyter from the terminal, try the following:
Open a new terminal, , type cd (with a space) and drag and drop the folder you wish to start jupyter in to the terminal. You need to drag and drop, this will flag the folder as being "ok to be accessed from application launched from the terminal" typing the path by hand won't help. Press enter, and then try to start jupyter from there.
If you have any error message in the terminal they should be helpful, try to also open the .ipynb files with a text editor to make sure they are not corrupted, and/or share them with somebody else to see if they can open it.

Related

Jupyter Notebook: Access to the file was denied

I'm trying to run a Jupyter notebook on Ubuntu 21.10. I've installed python, jupyter notebook, and all the various prerequisites. I added export PATH=$PATH:~/.local/bin to my bashrc so that the command jupyter notebook would be operational from the terminal.
When I call jupyter notebook from the terminal, I get the following error message from my browser:
Access to the file was denied.
The file at /home/username/.local/share/jupyter/runtime/nbserver-260094-open.html is not readable.
It may have been removed, moved, or file permissions may be preventing access.
I'm using the latest version of FireFox.
I've read a number of guides on this and it seems to be a permissions error, but none of the guides that I've used have resolved the issue. Using sudo does not help, in fact it causes Exception: Jupyter command "jupyter-notebook" not found. to be thrown.
That being said, I am still able to access the notebook server. If I go to the terminal and instead click on the localhost:8888 or IP address of the notebook server then it takes me to the notebook and everything runs without issue.
I would like to solve this so that when I run jupyter notebook I'm taken to the server and don't need to go back to the terminal window and click the IP address. It's inconvenient and can slow me down if I'm running multiple notebooks at once.
Any help on this issue would be greatly appreciated!
I had the same problem.
Ubuntu 20.04.3 LTS
Chromium Version 96.0.4664.110
This was the solution in my case:
Create the configuration file with this command:
jupyter notebook --generate-config
Edit the configuration file ~/.jupyter/jupyter_notebook_config.py and set:
c.NotebookApp.use_redirect_file = False
Make sure that this configuration parameter starts at the beginning of the line. If you leave one space at the beginning of the line, you will get the message that access to the file was denied.
Otherwise you can clean and reinstall JupyterLab
jupyter lab clean --all
pip3 install jupyterlab --force-reinstall
If anyone is curious, the reason for the problem is that the file:// URI scheme cannot access files in hidden directories directly under the home directory (~/.local in your case).
You can recreate the problem with:
mkdir ~/.test && echo "abc" > ~/.test/file.html && xdg-open ~/.test/file.html
I couldn't find any reference for this behaviour in RFC8089, and I also don't understand how the Jupyter authors missed this issue.
As LSeu suggested, the way to bypass the local redirection file, is to run:
echo "c.NotebookApp.use_redirect_file = False" >> ~/.jupyter/jupyter_notebook_config.py
Another solution is to run jupyter notebook --no-browser and (Ctrl)-click the link in the terminal.
For those running Firefox installed with snap:
I think this issue has more to do with firefox installed with Snap, which somewhere along the way disallows Firefox access to hidden directories inside the /home/user folder in its sandboxed environment.
Another solution not mentioned in this thread (if you don't want to use another browser install) is to set the JUPYTER_RUNTIME_DIR env variable to a non-hidden directory in the /home/user folder:
# Ubuntu 22.04.1 LTS
# append env variable to persistent user env file. requires relogging in
echo JUPYTER_RUNTIME_DIR=/home/user/jupyter_runtime >> ~/.pam_environment
reboot
Alternatively, try going directly to the other suggested URLs: http://localhost:8888/lab?token=<your-access-token> or http://127.0.0.1:8888/lab?token=<your-access-token> (which is what setting the ...use_redirect_file = False does)

Just installed Jupyter using Anaconda but can't run it using terminal. Says command not found

I just bought my very first Mac after using Windows my entire life and have been trying to install things. I am also still kind of a beginner at programming.
I installed Anaconda for Python 2.7 version, and then I installed the 3.7 version right after.
I tried going to terminal and typing jupyter notebook but it says:
zsh: command not found: jupyter
I am able to launch a jupyter notebook (I think) when I search for jupyter notebook in spotlight and executing the top hit.
I've been reading a lot on forums about this issue and see a lot of people talking about PATH which I am not really sure about.
I've seen people also post their which python information and theirs seem very different from mine:
which python3
usr/bin/python3
which python
usr/bin/python
Any help would be appreciated! Still learning how to set up this Mac. Thank you.
You might want to refer to this link https://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html
3.1.2. Change Jupyter Notebook startup folder (Mac OS)
To launch Jupyter Notebook App:
Click on spotlight, type terminal to open a terminal window.
Enter the startup folder by typing cd /some_folder_name.
Type jupyter notebook to launch the Jupyter Notebook App The notebook interface will appear in a new browser window or tab.
From what I can understand you are not changing to the startup directory of Jupyter.
You need to add jupyter to your path.
In your terminal, type in the following command:
export PATH="/PUT JUPYTER PATH HERE:$PATH"
Then try jupyter notebook
Reasoning: If installing using pip install --user, you must add the user-level bin directory to your PATH environment variable in order to launch jupyter lab

Why does jupyter notebook server keeps crashing when .ipynb files are opened?

I was able to use jupyter notebook 4 days ago. The only thing that changed was there was a firefox version update.
After that the server crashes everytime .ipynb files are opened. Even the directory will have a server error. I tried it both on Firefox and Google Chrome, both browsers will crash the server.
My only kernel is python3 and it always says "Kernel Busy". I tried resetting my pc and the jupyter notebook, but nothing seems to work.
The console showed:
The last 2 lines are causing the crash but I don't know how to fix it
When I type conda install jupyter in the anaconda prompt, I get something before it finishes as shown below. Maybe it might have a cause as to why it is having issues:
I created a new python environment and installed python, matplotlib, pandas, jupyter and it still crashes
Please uninstall and re-install all the below items:
ipykernel
ipython
jupyter_client
jupyter_core
traitlets
ipython_genutils
Additionally, if you're going to install with conda, follow below command.
run conda clean -tipsy
This command will clean up conda caches before you start.
Reference:
https://github.com/jupyter/notebook/issues/1892
Do you let Jupyter start the browser? If so, disable that and start the browser manually. I don't see how the zmq error messages could be related to the browser startup, but since you say that the only change was a browser update, that's worth a shot.
Check which version of pyzmq is installed. If Jupyter Notebook and the kernel are in different conda envs, check both and make sure they are on the same version and build. Try upgrading or downgrading to different versions. According to Anaconda issue 8932, there are problems with pyzmq on Windows. And a new build for win32 was released about two weeks ago - though I would expect win64 builds to be used nowadays.
I also found some recommendations for a similar error message to yours in Spyder issue 6097. The first one is to try without firewall and/or antivirus. You might have picked up a new firewall rule unknowingly. Trying different versions of pyzmq is also mentioned there.
I am sharing this solution in case someone needs it in the future.
I have just faced the same problem a hour ago. This was the message I was getting in the terminal. And the jupyter keeps restarting.
ModuleNotFoundError: No module named 'html.entities'; 'html' is not a package
[I 00:44:32.436 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
After Searching through the internet when I can not find the solution. I fixed it by removing the .HTML files I had in the directory. After moving those file jupyter started working parfectly.
I just had a similar problem - for me, it was casued by a non-existing %temp% directory (I have %temp% mapped to a ram disk, and the temp folder on it wasn't created yet).
Creating the folder pointed to by %temp% solved the issue.
All my environments were working totally fine but suddenly after restarting the system, the jupyter notebook from an environment was not opening or it was suddenly crashing. Tried form anaconda prompt but getting "Unable to create Process...
All my DL dependencies were on this environment and I didn't want to create new environment completely installing all the required dependencies.
Solution: I opened the Anaconda Navigator and cloned old_env to new_env and it worked magically. I could able to open the jupyter notebook successfully and all dependencies were working fine. Hope it helps

PyCharm Jupyter notebook : Add Jupyter to the interpreter of the current project

I have a new project in PyCharm under it the project, I create a jupyter notebook
but when I run it I keep getting this error
Add Jupyter to the interpreter of the current project.
I cant figure out what to do, I have reset the
Project Interpretor
But no use
You need to install jupyter for the project interpreter or the virtualenv that you use:
pip install jupyter
PyCharm support for the Jupyter Notebook is shaky IMO. You will probably need to restart it, and respond to dialog windows trying to connect to the default Notebook server location, localhost:8888. On my machine, canceling that request to connect strangely helps to finally see the output of the cells within PyCharm.

Pycharm Jupyter Notebook `PYTHONPATH`?

System information
Mac OS X 10.12 Sierra
Pycharm 2016.2.3
Python 3.5.1
Jupyter 4.1.0
Question
When I'm using Jupyter Notebook under Pycharm, it doesn't seem to include my current working directory, or the source root directory, in the PYTHONPATH of the currently active Jupyter Notebook. This is unlike the behaviour of ordinary .py files, for which Pycharm automatically includes its current directory and the project source root directory in the PYTHONPATH. So, is it possible to set Pycharm to automatically include the project source root directory in the PYTHONPATH for Jupyter Notebooks run under Pycharm?
It turns out, in a past endeavour, I modified my jupyter_notebook_config.py in %USER%\.jupyter folder. Looked at lines as follows:
## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = 'D:\\Works\\GitHub\\Jupyter\\'
The line under the ##, indicates the override path, evidently.
When I commented it out...Pycharm all of the sudden successfully launched with pwd of the file (location of the .ipynb). good luck, hth.
Pycharm 2019.1 has done an overhaul of Jupyter support. Jetbrains says this in reference to Pycharm 2019.1: "Jupyter Notebook support in PyCharm was redesigned from the ground up."
So, as of Pycharm 2019.1, you can now set Pycharm to include the project source root directory for Jupyter Notebooks.
See this page of Pycharm 2019.1 help.
There's a bunch of ways to mess with the environment, but the PyCharm specific way that worked for me was to make the directory with my source in it a PyCharm "sources root" as described here: https://www.jetbrains.com/help/pycharm/content-root.html
This can be done from the context menu of a directory in the navigator, or from the "Project Structure" settings pane.
This seems to update the PYTHONPATH as well as sorting out things like autocomplete.
For anyone using the free version of PyCharm, which has no direct Jupyter Notebook support, there's a simple workaround:
Go to PyCharm "Terminal" tab at the bottom (NOT to be confused with the Python console tab!)
[NOTE: steps 2 and 3 are for Window7; on other OS's, just research how to set environment variables thru the terminal or command prompt]
Issue the command:
set PYTHONPATH=\path_to_your_project_root_folder\
EXAMPLE on Windows: set PYTHONPATH=\Docs\- MY CODE\my_project_root_folder\
Optionally, you may verify that the environmental variable got set by issuing the command: set PYTHONPATH
Issue the command: jupyter notebook
That's all! A new browser tab will open up... and, insider any notebook, you can verify the path by issuing the python commands:
import sys
sys.path

Categories