Is there some way to tell jupyter notebook what the default conda env should be when creating new notebooks? Launching it on AWS Deep Learning AMI's gives me a pretty long list, but I really only care about one specific env.
If you go to your terminal first and activate the virtual environment:
$ source venv/bin/activate
or
$ conda activate venv
for conda environment.
And after that step, do the following:
$ jupyter notebook
And when you make a new script it should give you the option for chosing python3/python2, chose the one that solves your purpose. And this script will be using the activated environment. You can check it by importing a libraray specific to that environment.
Related
I've got 10 jupyter notebooks, each with many unique package dependencies (that conflict), so I've created a different anaconda environment for each notebook. Each notebook relies on the output of the previous one, which I store and read from local csv files.
Right now I am running each jupyter notebook manually (with their own anaconda environment) to get the final result. Is there a way to run a single script that runs the code of all the jupyter notebooks sequentially (with the correct anaconda environment for each one)?
You could do it in python and use runipy. You just have to install it with:
pip install runipy
An example on how to use it from the docs:
from runipy.notebook_runner import NotebookRunner
from IPython.nbformat.current import read
notebook = read(open("MyNotebook.ipynb"), 'json')
r = NotebookRunner(notebook)
r.run_notebook()
If you want to run each notebook in a different environment, you can activate each conda environmentfrom a python script. There are multiple ways to do so, one of them is this:
subprocess.run('source activate environment-name && "enter command here" && source deactivate', shell=True)
Replace the "enter command here" with the command you want to run. You
don't need the "source deactivate" at the end of the command but it's
included just to be safe.
This will temporarily activate the Anaconda environment for the
duration of the subprocess call, after which the environment will
revert back to your original environment. This is useful for running
any commands you want in a temporary environment.
After seeing this post on how to set the start-up folder for Jupyter Notebooks, I looked for how to do so for specific conda environments and haven't found an answer.
Is there a way to open up a Jupyter notebook in a location that is different depending on which conda environment within which you're activating it? I'm looking for a solution like the one above, where I could change c.NotebookApp.notebook_dir = '/the/path/to/home/folder/', but in some environment-specific config file.
I guess an alternative would be to set some macro to activate the environment, cd to the desired folder location for this environment, then run jupyter notebook from that location.
I was able to generate a DOSKEY macro to do the job. I combined this answer which shows how to set persistent aliases (macros) in command prompt, with this answer which shows how to use multiple separate commands in a DOSKEY macro. As a summary here (mostly from Argyll's answer in the above persistent macro/DOSKEY post):
Create a file called something like alias.cmd
Insert the macro to automatically activate a conda environment, change file locations, and run a jupyter notebook from that location:
doskey start_myEnv = conda activate myEnv $T cd C:\Users\user\path\to\my\notebooks\ $T jupyter notebook
Run regedit and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
or HKEY_CURRENT_USER\Software\Microsoft\Command Processor if not on Windows 10.
Add a String entry with the name AutoRun with the value set as the full path to the alias.cmd file.
Anytime you open the command prompt, executing start_myEnv will now activate myEnv, change to the folder that relates to that environment, and start a jupyter notebook.
I use anaconda to install jupyter
Following is my command
$ activate demo ....demo is my environment name
$ conda install jupyter
$ jupyter notebook
and then it will get following error message
[C 10:39:17.591 NotebookApp] Bad config encountered during initialization:
[C 10:39:17.594 NotebookApp] Could not decode 'C:\Users\\xbeG\xa8|\xa5\xe0\.jupyter' for unicode trait 'config_dir' of a NotebookApp instance.
I think my path under C: has chinese, so it can't decode properly.
I also see some similar issue https://github.com/jupyterlab/jupyterlab/issues/5345
but this solution is no help to me, because I use window, I also tried to use
chcp in CMD to change language. It doesn't work too.( I have tried chcp950 ,chcp65001,chcp436)
Are there anyone have idea about my problem?
I also have another problem is that when I conda install jupyter , it seems
to be installed in C: automatically, I want to know are there any method install it to specific path? If it can achieve, I think there is no decode problem because path under D: didn't have chinese.
Thanks all of your help.
my environment:
Python 3.6.5
conda 4.6.11
Not sure if it'll fix your problem but you can install conda packages to a different directory by creating a different environment.
conda create --prefix D:\my_conda python=3.7
activate D:\my_conda
I think you can create .condarc file inside the root of this new conda environment and it'll override the one in your home directory.
Does anyone know how to set custom.css in for a conda environment?
I created a new environment using
conda create -n myenv
But it doesn't use the same custom.css I created in the default environment.
Any idea where I should put the custom.css file to get Jupyter to use it?
I'm using Windows 7.
See the docs here for info on where paths are located by default (for conda you'd probably be looking at the {sys.prefix}/etc/jupyter path).
Or you could just run jupyter --paths in your conda environment shell to find out where it is looking for custom files.
Once you have the Jupyter notebook installed using the Google Initialisation script is it possible to create and activate a conda environment on all the worker nodes?
Do I need to ssh onto each worker and create the same environment or is there a way to accomplish the same via a notebook if the number of modules to add is small?
Once you have a cluster up, there is not a great way to re-configure all workers.
If you create a new cluster the conda initialization action might be helpful.