-
-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for activating conda environments in the kernel.json launch script? #416
Comments
I like this idea overall. I thought the new pattern was |
Let me get a response from the conda folks and I'll update this issue |
Yeah, on Windows if using cmd or Powershell is /path/to/activate but some of us only use Git Bash on Windows. 😀 |
I was just having what I think is a related issue that I documented on stack overflow... Basically I have my main python installation from python.org using pip to install jupyter. I then need to use a conda environment for something and I would like to be able to use my conda installation from my existing Jupyter install as a kernel. I successfully added the kernel to the list and can select it from within JupyterLab. Unfortunately, upon kernel activation, zmq fails to load with DLL errors because conda's If I instead first run the anaconda prompt which activates the base environment of my miniconda installation, then explicitly run my python.org/pip -based Jupyter server, I can now run the conda-based kernel or the python.org based kernel just fine. I think it's because activating the environment enables the conda DLL's to be found. I understand that |
I have the same problem trying to setup an environment/kernel (gis) to be launched from jupyter lab installed on the default environment (base).
However, when I launch from jupyter lab the gis python kernel installed via
I get the following error
|
I have the same problem with shapely / geos on Windows. If the conda environment is not loaded, many packages do work by just specifying the full path to python in "kernel.json", but importing "geoviews" fails since some of the shapely / geos DLLs on windows do not work correctly without loading the conda environment first. My simple work-around is to launch the kernel via a bat file that loads conda Create a launch.bat file in the kernel directory containing the following (geoviews is the name of my environment): call C:\anaconda3\condabin\conda.bat activate geoviews
python -m ipykernel_launcher -f %*
call C:\anaconda3\condabin\conda.bat deactivate Then specify a kernel.json file as follows (notebook is the environment running jupyter-lab in this case): {
"argv": [
"cmd.exe",
"/C",
"C:\\anaconda3\\envs\\notebook\\share\\jupyter\\kernels\\geoviews\\launch.bat",
"{connection_file}"
],
"display_name": "geoviews",
"language": "python"
} I tried to do this without the bat file, but there seems to be a difference between launching conda.bat with and without "call" in front. By using cmd.exe and "call" it works. PS: I do not have conda installed in the PATH (just as recommended by the installer) so this should work for must people, I think ... |
Thanks TormodlLandet! I tried your method and it works. |
Any progress on this issue? Would love to contribute or have support for this feature |
{
"argv": [
"python",
"-m",
"nb_conda_kernels.runner",
"/usr/local/Miniconda3",
"/home/mathause/.conda/envs/test_basemap",
"/home/mathause/.conda/envs/test_basemap/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python (test_basemap)",
"language": "python"
} |
bump here! If someone has a clear path, i'd be down to code a bit. |
Hi ipykernel team! When using a Jupyter notebook with a conda environment,
!conda
commands do not operate on the conda environment that the user's kernel is running in. At least, not without some surgery to the kernel.json file.Below, I motivate the use-case for why you want to properly activate a conda environment before launching a kernel out of it. Is there interest from the ipykernel team in accepting a pull-request that adds this functionality to the
install
subcommand on ipykernel?First pass at a proposed API is to add a
--conda
flag to the call so that it would look likepython -m ipykernel install --user --name <kernel name> --conda
. But, before any work is done to add this to the ipykernel code base, let's discuss in an issue.Motivating the problem
@parente and I found that it was a pretty common user expectation that they could add a package to their environment when running in a jupyter notebook by executing
!conda install <whatever package>
. As such, we (actually mostly @parente) ended up writing kernda so we could addsource activate <conda env>
to the launch script in the kernel.json file in a reliable way.The usage is as follows:
conda create -n moviepy moviepy ipykernel -c conda-forge
conda activate moviepy
,python -m ipykernel install --user --name moviepy
At this point, let's inspect the kernel.json file:
This kernel will successfully launch a kernel out of the
moviepy
conda environment, but it notably is not activating the environment. This has two main ramifications:I'll track down a few of these packages to provide some concrete examplesa. https://github.com/conda-forge/proj.4-feedstock/blob/master/recipe/scripts/activate.sh
b. https://github.com/conda-forge/qgis-feedstock/blob/master/recipe/scripts/activate.sh
c. (will continue looking for more)
!conda
operates on the conda environment that the kernel is running out of.So, let's use kernda to edit this kernel.json file to add
source activate
to the script:This will output the following that you can either redirect into the proper file (or you can use the
-i
flag to overwrite the original):At this point we will have a kernel that has proper conda activation and gives the user the
!conda
functionality in their notebook.edit: add activate.d example
The text was updated successfully, but these errors were encountered: