I have created a conda environment called Foo. After activating this environment I installed Kedro with pip, since conda was giving me a conflict. Even though I'm inside the Foo environment, when I run:
kedro jupyter lab
It picks up the modules from my base environment, not the Foo environment. Any idea, why this is happening, and how I can change what modules my notebook detect?
Edit
By mangling with my code I found out that on the \AppData\Roaming\jupyter\kernels\kedro_project\kernel.json it was calling the python from the base environment, not the Foo environment. I changed it manually, but is there a mode automatic way of setting the \AppData\Roaming\jupyter\kernels\kedro_project\kernel.json to use the current environment I'm on?
The custom Kedro kernel spec is a feature that I recently added to Kedro. When you run kedro jupyter lab/notebook it should automatically pick up on the conda environment without you needing to manually edit the kernel.json file. I tested this myself to check that it worked so I'm very interested in understanding what's going on here!
The function _create_kernel is what makes the the Kedro kernel spec. The docstring for that explains what's going on, but in short we delegate to ipykernel.kernelspec.install. This generates a kernelspec that points towards the Python path given by sys.executable (see make_ipkernel_cmd). In theory this should already point towards the correct Python path, which takes account of the conda environment.
It's worth checking which kedro to see which conda environment that points to, and if we need to debug further then please do raise an issue on our Github repo. I'd definitely like to get to the bottom of this and understand where the problem is.
P.S. you can also do a plain jupyter lab/notebook to launch a kernel with the right conda environment and then run %load_ext kedro.extras.extensions.ipython in the first cell. This is basically equivalent to using the Kedro kernelspec, which loads the Kedro IPython extension automatically.
This is likely a problem with jupyter. I'd suggest trying to run jupyter notebook and understand if it is down to kedro or jupyter.
I remember facing something similar due to some jupyter problem but don't remember how I fixed it. I remember trying some solutions from
this issue on jupyter.
Try do pip install jupyterlab in your foo enviornment, Jupyter Kernel is a different concept and acts weird sometimes.
Related
I have separate Conda environments for work and outside projects. I start JupyterLab with a simple jupyter lab command within an Anaconda command prompt (on Windows, but my issue occurs on MacOS and Linux too). I conda activate the relevant environment before invoking the startup command. However, JupyterLab always auto-reopens the most recent set of notebooks I had open, without regard to which Conda environment I had been working in before vs. now. It also defaults to the associated working directory (I know that I can at least explicitly specify a working directory on startup, though). Is there a way for me to get JupyterLab to associate a certain set of notebooks with a specific Conda environment?
Note that this question is separate from issues concerning kernels. I use nb_conda_kernels to manage kernels for each notebook, and I have a handle on how that works. I'm just wondering about this auto-reopen feature. Does anyone know about how it works (i.e., where it draws the last-open files from)?
As a slight side note, it seems to often act like all of the newly-reopened files are unsaved, even after I save them all and do a simple restart of JupyterLab. I'm curious about why that happens too, but it's less important.
I am using VS Code for the first time, trying to run a .py file. However it is struggling to find the packages I have in conda (no virtual env, just base).
I have changed the Python interpreter so that it's now using "...64-bit (conda)".
I have also added "python.defaultInterpreterPath": "C:\\Users\\username\\anaconda3\\python.exe" into the JSON settings.
When I then run the file, it finds some packages but not all: it finds os, random and collections but not any others...
Also when I run print(sys.executable) I get "C:\Users\username\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe". I think this should instead be pointing towards the python.exe in anaconda3...
Any assistance with accessing my packages in conda would be appreciated!
As always, read the docs:
https://code.visualstudio.com/docs/python/environments#_create-a-conda-environment
It contains several hints of what can go wrong with conda environments in VSCode.
Most important for you:
A conda environment has to activated before you can use it and obviously this is not happening in your case. The terminal must show a (base) or (Anaconda3) on the prompt. Just pointing to the python.exe is not good enough.
"python.defaultInterpreterPath" only works when you first open your workspace. After you changed it, it will be stored in the database.
You need to make sure you have switched the python interpreter to which you want to use. It would be like this:
I have tried all of the things here on stack and on other sites with no joy...
I'd appreciate any suggestions please.
I have installed Jupyter and Notebook using pip3 - please note that I have updated pip3 before doing so.
However when trying to check the version of both jupyter --version and notebook --version my terminal is returning no command found. I have also tried to run jupyter, notebook and jupyter notebook and I am still getting the same message.
I have spent nearly two days now trying to sort this out... I'm on the verge of giving up.
I have a feeling it has something to do with my PATH variable maybe not pointing to where the jupyter executable is stored but I don't know how to find out where notebook and jupyter are stored on my system.
many thanks in advance
Bobby
You should be able to run jupyter with python -m even if the PATH variable is not set up correctly.
python -m jupyter notebook
you can check the PATH variables on Windows if you search in with the windows search function for env and then click on Edit the system environment variables > Environment Variables....
The path variable is a list of paths that the terminal checks for commands.
I didn`t work on Mac for a long time, so not sure how similar linux and mac command line still are, but on debian you control your path variable like this.
View paths:
echo $PATH
/usr/local/bin:/usr/bin:/bin
Add a path:
export PATH=$PATH:/mynewpath
For constant export add to ~/.bashrc
To view the path of the pip package, you can use
pip3 show jupyter
When jupyter-notebook works and jupyter notebook does not. It looks to me like a symlink thing. Or a Mac-specific problem.
So to summarise this is what I have found on this issue (in my experience):
to run the jupyter app you can use the jupyter-notebook command and this works, but why? This is because, the jupyter-notebook is stored in usr/local/bin which is normally always stored in the PATH variable.
I then discovered that the jupyter notebook or jupyter --version command will now work if I did the following:
open my ./bash_profile file
add the following to the bottom of the file: export PATH=$PATH:/Users/your-home-directory/Library/Python/3.7/bin
this should add the location of where jupyter is located to your path variable.
Alternatively, as suggested by #HackLab we can also do the following:
python3 -m jupyter notebook
Hopefully, this will give anyone else having the same issues I had an easier time resolving this issue.
I've found a solution from the documentation over at Jupyter https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html but I am still curious.
It states that to run the application to use the command jupyter-notebook and hey-presto! It does seem to work now. But, why is this when nearly everywhere else I have read that to run the app we just type the command jupyter notebook.
Also, if I do need to check the version of any of the Jupyter files how do I go about this now, if jupyter --version and notebook --version still don't work.
Also, how do I go about finding these files in my file system if I have no idea where they are located? And how do I go about adding these to my path so that I can, for example, check the version of these programs?
Will pip3 automatically update this software as and when needed?
Thanks again in advance
have you tried locate Jupiter? It may tell you where jupyter is on your system.
Also, why not try installing jupyter via anaconda to avoid the hassle?
I definitely would recommend going through anaconda which makes everything a lot easier.
The following is the link with step by step instructions: https://jupyter.readthedocs.io/en/latest/install.html
I've replicated Slack's API demo in a text editor and the terminal, but just for fun, I wanted to do it again using Jupyter notebook. I used the same virtual environment so as to rule-out dependency issues and the code was the same (cloned from the master repo). But for some reason, I'm always getting ModuleNotFound errors when I try to run the code in Jupyter cells and import the necessary packages.
I even re-built a fresh virtual environment, and ran the demo at a terminal from within Jupyter, and running the scripts works fine. I just doesn't execute in the notebook environment.
I'm using the same kernel across my Python interpreters, and I always start my virtualenv session before launching the notebook.
Anyone have any ideas why this would be the case?
Well, DUH. It was just a matter of uninstalling/reinstalling the package in a fresh virtual environment (and I'm pretty sure the latter wasn't absolutely necessary).
Thanks to this comment on Github for the guidance.
I installed Anaconda using defaults.(i'd post a .png of button i pushed but i don't have the rep for more than two links)
I am following the test drive for Anaconda Test Drive and had a problem with Section #2 - Environments.
Following the provided code I created several environments, switched between them, and then deactivated one.
When i deactivated the environment I went to place where 'conda' is not longer a recognized command.
Anaconda Terminal Session:
i open anaconda terminal and begin in the root directory.
i successfully activate the environment 'snowflakes'.
i issue command 'deactivate' which should return me to root directory.
however, i am now farther up the file structure where 'conda' is not a recognized command. i suppose i can issue 'cd appdata\local\continuum\anaconda2' to solve the problem but i'm thinking i've probably messed something up and would like to fix the problem.
any suggestions what to do?
some things i encountered before posting question:
1. when i installed anaconda there was a checkbox that had something to do with PATH - but anaconda encouraged me NOT to check the box - so i did not.
2. I have also read some posts here discussing that one should have a simple path so I wonder if I should install this someplace other than the default path - which is kinda long as you can see in the terminal session.
any help would be appreciated.
I think I know why the command conda is not being recognized.
When you typed the first time (in your screenshot of the terminal) you were at C:\Users\RAdams.GNSMEM\AppData\Local\Continuum\Anaconda2. Inside this folder you should have the executable conda, so when you called it inside this folder makes sense that it may be executed. However, when you called conda outside of this folder (the second time in your screenshot) you had no executable file named conda to be executed. If you wanted to call the command conda without the need of being in the Anaconda2 folder, you should have made this command be inside your PATH variable. Probably that's what the install manager asked you to do and you refused (maybe it recommended you against it because you're dealing with Windows and it may be somewhat different from what happens in Linux).
EDIT:
After taking another look at your screenshot, I saw that the C:\Users\RAdams.GNSMEM\AppData\Local\Continuum\Anaconda2 was, in fact, your environment. You activated this environment and was in the folder C:\Users\RAdams.GNSMEM. Being in this environment makes you able to call the executable files within it even when outside of it. The thing is that you activated snowflakes (and I think that the other environment was automatically deactivated) after that and then deactivated it. So you had no environments loaded when you called conda the last time. Your environments are pretty OK, I guess.