I am just getting started trying to learn Python for course assignments. Our teacher has mandated using iPython notebooks, so I have installed Enthought Python AND ipython on my Mac.
The iPython home directory is /users/me/.ipython
I have used the ipython profile create command to create the file
.ipython/profile_default/ipython_config.py
but I don't know how to access this file or what to put in it.
My objective is to set the default file path to:
/users/me/documents/classes/analytics/hw1
so that code in my ipython notebook will automatically know where to look for data files.
Please help!
You can change the default path to your notebook files. Search in ipython_notebook_config.py for a setting notebook_dir.
The default folder for accessing files is the folder that your notebook is in. If you need to change that, then at the start of the notebook, add a command like this:
%cd /users/me/documents/classes/analytics/hw1
Related
In Windows 10 cmd.exe I can start jupyter in a current directory by following command:
jupyter notebook --notebook-dir="."
The current directory is C:\Users\Евгений\Documents\GitHub\sandbox
However, when I start simply jupyter notebook in a current directory above my working directory for jupyter is D:/git:
λ cd
C:\Users\Евгений\Documents\GitHub\sandbox
λ jupyter notebook
[I 14:46:44.273 NotebookApp] The port 8888 is already in use, trying another port.
[I 14:46:44.304 NotebookApp] JupyterLab beta preview extension loaded from D:\Anaconda3\lib\site-packages\jupyterlab
[I 14:46:44.304 NotebookApp] JupyterLab application directory is D:\Anaconda3\share\jupyter\lab
[I 14:46:44.571 NotebookApp] Serving notebooks from local directory: D:/git
Note the last line Serving notebooks from local directory: D:/git. Where is D:/git may be coming from? Are there environment variables other than these affecting working directory choice?
My %USERPROFILE%/.jupyter is totally empty.
jupyter --config-dir directs to C:\Users\Евгений\.jupyter, it is %USERPROFILE%/.jupyter.
I read various threads about jupyter invoke, in particular:
this large thread suggests jupyter notebook will behave differently in cmd.exe and Anaconda prompt, without further details though
Problems with configuring Jupyter start directory addresses an issue with Windows shortcut, similar to this Windows app start steps
this post proposes wrapping --notebook-dir="." key into a .bat file
My other thought is that %USERPROFILE% with non-Latin character is not be recongnisable by jupyter, but %USERPROFILE%/.jupyter is empty anyways.
You must generate the configuration of Jupyter.
jupyter notebook --generate-config
Navigate to your folder and the folder .jupyter (C:\Users\%username%\.jupyter)
You will find a file called jupyter_notebook_config.py
Edit it with notepad++ for exemple and locate c.NotebookApp.notebook_dir
Between ' ' put the path you want. For exemple :
c.NotebookApp.notebook_dir = 'C:/Users/Евгений/Documents/GitHub/sandbox'
Save it and start Jupyter without specifying a path
Be careful, the characters in your username may be a problem.
Keep me informed.
Use the jupyter notebook config file:
Open cmd (or Anaconda Prompt) and run jupyter notebook --generate-config.
This writes a file to C:\Users\username\.jupyter\jupyter_notebook_config.py.
Browse to the file location and open it in an Editor
Search for the following line in the file: #c.NotebookApp.notebook_dir = ''
Replace by c.NotebookApp.notebook_dir = 'D:/git'
Make sure you use forward slashes in your path
Remove the # at the beginning of the line to allow the line to execute
Using docker and the images maintained by the Jupyter team:
docker run -v `pwd`:/home/jovyan -p 8890:8888 jupyter/scipy-notebook
I installed Anaconda on my Windows 10 machine.
I have a few Jupyter notebooks on my pc and I would like to associate them with Jupyter, so they can be opened by double-clicking on the file, to avoid having to open Jupyter and navigate to the notebooks folders each time. Is this possible?
All notebooks should open in the same Jupiter Kernel (same localhost in the browser address bar), without starting a new kernel for every file I click.
PS I asked here because I figured this question to be more of interest for programmers, but if you think it would be more suited for SuperUser, I'll flag it for migration.
Install nbopen: https://github.com/takluyver/nbopen
pip install nbopen
python -m nbopen.install_win
Now you can double-click on *.ipynb files:
If you have Jupyter installed with Anaconda you can do the following.
Create a little batch file (e.g. start_jupyter_notebook.bat) with the content (the commands are from the Jupyter shortcut):
#echo off
set ANACONDAPATH=C:\_work\_programs\Anaconda3
%ANACONDAPATH%\python.exe %ANACONDAPATH%\cwp.py %ANACONDAPATH%^
%ANACONDAPATH%\python.exe %ANACONDAPATH%\Scripts\jupyter-notebook-script.py %1
(of course you will have to change the ANACONDAPATH to your installation)
Then go to one .ipynb file of your choice, right-click on it, go to properties --> open with --> change and select your created batch file.
I am pretty sure this can also be setup for any other Python/Jupyter installation.
P.S. The cwp.py file sets up some environment variables. I guess this is the reason why fredm73's answer did not work for everybody. Apart from that my answer is quite similar in the end.
associate .ipnyb with jupyter-notebook.exe
On Windows 10: control panel/Programs/Default Programs/Associate a file type or protocol with a program/Choose default apps by file type
Look at the list of extensions, find '.ipnyb'. Click on icon and locate the jupyter notebook program. In my Anaconda installation, it is found at
anaconda/scripts/jupyter-notebook.exe
Easiest way for me - double click on the .ipnyb file. When prompted to pick a program to open the extension with go to /ProgramData/Anaconda3/Scripts and locate the jupyter-notebook.exe file and click it.
NOTE - to access the ProgramData folder you will need to view hidden folders in the Windows explorer or access it by typing %programdata% in the navigation line:
You can use nbopen on pip and run the module:
py -m pip install -U nbopen
py -m nbopen.install_win
For those who installed nbopen in Anaconda but it does not work:
Use Regedit to search for a directory called Jupyter.nbopen, and navigate to its shell\open\command. It should be something like:
HKEY_USERS\****\Software\Classes\Jupyter.nbopen\shell\open\command
Then, change the default to: (Modify the path if you are not installed in default location)
"C:\ProgramData\Anaconda3\pythonw.exe" "C:\ProgramData\Anaconda3\cwp.py" "C:\ProgramData\Anaconda3" "C:\ProgramData\Anaconda3\pythonw.exe" -m nbopen "%1"
The reason behind this is that cwp.py makes sure that the Jupyter is running in Anaconda instead of other Python environments.
Then it should work, although it will activate two invisible pythonw process running in the background.
Just look into your file directory and look for programs that can open the file type and set it as your default app opener but you need to take into consideration that if you want to use Jupiter notebook, you can run jupyternotebook app and locate the file from the jupyter notebook directory.
Secondly, ensure you have added your python.eex to path and run directly from your command prompt. See pictures in the screenshot
Find the jupter-notebook.exe in the C:\Users\my_username\Anaconda3\Scripts folder. Copy the address. When you're opening the .ipnyb file double click ( if first time) or just do open with and there in the menu you can tick the 'always use this' option and locate the notebook from 'look more programs' option in the menu.
I have installed anaconda on C:\Users\My_name\AppData\Local\Continuum\Anaconda2, the issue is that whenever I launch jupyternotebook or any other from the anaconda navigator the starting directory is a external network location Z:. I want jupyter to be installed and run on C:\ how do I solve it?
Here is a copy of the anaconda command prompt so you better understand what I mean.
I have already reinstalled anaconda making sure that I select the C:\ directory, even installing offline so the computer has no acces to Z:, but the result is the same. Any ideas on how to solve it?
I defined a new windows PATH variable to ~\Anaconda2\Scripts. Then I can start jupyter notebook anywhere just by tiping "jupyter notebook" on the command line.
For MacOS, edit this file:
/Users/{your user name}/anaconda/bin/jupyter_mac.command
Original was:
DIR=$(dirname $0)<br/>
$DIR/jupyter-notebook
I added a line:
DIR=$(dirname $0)<br/>
cd /Users/{your user name}/{whatever folder you want}/<br/>
$DIR/jupyter-notebook
This way, Jupyter notebook starts directory you want. Be careful about folder names with space. Use \ before the space. For example, the Google Drive folder shoule be:
cd /Users/{your user name}/Google\ Drive/
I used to be able to change the default start up folder for Jupyter (the folder Jupyter displays in browser when it was first started) by modifying the "start in" option of the Notebook launch icon's properties on Windows, as described here and here.
However, this is not working any more after I recently installed Anaconda 3. Even though I changed the "start in" folder to the folder I wish, the browser still goes to "Documents" folder by default. I tried doing this as admin, still didn't work. Any suggestions? Thanks!
Although a permanent fix is still not found, I do have the following workaround that works great!
Using the way described here, change the start up dir for Anaconda prompt, then launch it and make sure the default folder is the one you want, and type "jupyter notebook". There! The notebook should launch in your desired folder.
UPDATE:
You can also directly launch Anaconda Prompt, then use cd C:\Users\Name\Folder to navigate into the folder where your iPython notebook files are located, and then use jupyter notebook or jupyter notebook myfile.ipynb to start working!
The only thing that worked for me to permanently fix the default working directory is by using this comment by MrFancypants.
In your default directory (documents), there is a hidden folder /.jupyter and within it a config python file.
you can edit it and change the line
## The directory to use for notebooks and kernels.
#c.NotebookApp.notebook_dir = ''
to
## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = 'ENTER_PATH_HERE'
where you should put your favorite path instead of 'ENTER_PATH_HERE.
Normally, I launch jupyter from a new bash terminal:
~$ jupyter notebook
and then navigate down the tree to the files I want to work at.
I just did it from a terminal that was already running at a different path:
~/blah/blah/blah$ jupyter notebook
and realized that that directory becomes the home for jupyter. I wanted to work at a file located at, say ~/blah/thingy/luis.ipynb, but couldn't find my way up.
How do I navigate the directory tree upwards in jupyter notebook?
As explained in https://github.com/ipython/ipython/issues/7751, it is not possible to navigate to the parent directory for security reasons:
The kernel might not be python, nor on the same machine than the
server, nor do you need a running kernel to use server API(s).
If you want, you can ask for more information in the aforementioned GitHub issue.
As edwinksl pointed out it is not possible for security reasons. See https://github.com/jupyter/notebook/issues/2032.
But if you want to keep your luis.ipynb file in its original location and still be able to access it from Jupyter Notebook browser, you can create a symlink to it in your running Jupyter Notebook directory:
ln -s ~/blah/thingy/luis.ipynb ~/blah/blah/blah/
For more details on symlinks see https://www.howtogeek.com/297721/how-to-create-and-use-symbolic-links-aka-symlinks-on-a-mac/