windows anaconda environment not working in jupyter notebook - python

i'm created a conda environment
conda create -n tfgpu tensorflow-gpu
conda activate tfgpu
but now after running
(tfgpu) > jupyter notebook
I can't import tensoflow as tf, notebook doesn't load this environment!
Why it's happen?

My problem is solved after:
https://stackoverflow.com/a/44786736/12370909
conda create -n tfgpu tensorflow-gpu
conda activate tfgpu
python -m ipykernel install --user --name tfgpu --display-name "Python (tfgpu)"
jupyter notebook
Then you could be able to create a new Notebook using your environment by selecting "Python (tfgpu)" from the drop-down list.

Related

Python New Env created by Anaconda Prompt not showing in Jupyter Notebook kernel list

I created a new python env using Anaconda Prompt by using the following steps:
conda create --name py3-TF2.0 python=3
conda activate py3-TF2.0
conda install tensorflow
pip install --upgrade tensorflow
pip install ipykernel
then i restarted anaconda and opened jupyter notebook.
The problem is when i open a new notebook and go to kernel to choose the new env i could not find the env i created (p3-TF2.0)
however, when I use conda info --envs, i find the new env created.
what is missing here?
thanks in advance
After activating the environment, try running:
python -m ipykernel install --user --name py3-TF2.0 --display-name "py3-TF2.0"
If this still isn't pointing to the correct environment (i.e. you can't import packages you know you installed in that environment), remove the py3-TF2.0 kernel that's broken with jupyter kernelspec remove py3-TF2.0.
Then run <your_path_to>/anaconda3/envs/py3-TF2.0/bin/python -m ipykernel install --user --name py3-TF2.0 --display-name "py3_TF2.0".
Additional help on Jupyter Kernels.

Conda install packages from jupyter notebook

I have used !{sys.executable} -m pip install to install packages i want to use in my jupyter notebooks.
Now i also want to install some packaged by conda and use in the same notebooks.
This is the command i run and the error message
They ask us to create a separate conda environment. I am confused about this.
Do we need to create a new conda enviroment everytime we need new packages?
What is the correct way to install and access conda packages on jupyter python notebook?
You shouldn't in principle install from the jupyter notebook but from the terminal/cmd.
You can create an enviroment >conda create --name myenv
And activate it: >conda activate myenv
now everything you install will be restricted to myenv. for example conda install numpy
To use the packages in myenv in jupyter simply open jupyter with your enviroment active:
>conda activate myenv
>jupyter notebook
Note that you have to install jupyter in your enviroment too: conda install jupyter

Jupyter and conda: error when cloning environment

I have created multiple conda environments in order to test compatibility of installed packages. I use conda create -n test02 --clone test01 to create environment test02 as a clone of test01. I activate test02, install new packages and start instance of python from which I import new packages with no problem. The problem arises when I launch jupyter notebook or qtconsole and try to import newly installed package and get import error: no module named 'xxx'. I do a sys.executable and see that jupyter is running python from the old environment (test01) I cloned the new one from. Why is this happening? Can I change it in config file somewhere and where might I find this file?
edit: more info
jupyter --paths for both environments share path entry for config and data in the same environment directory
(test01) PS C:\Users\Aka> jupyter --paths
config:
C:\Users\Aka\.jupyter
c:\users\aka\miniconda3\envs\test01\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\test01\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
(test01) PS C:\Users\Aka> conda activate test02
(test02) PS C:\Users\Aka> jupyter --paths
config:
C:\Users\Aka\.jupyter
c:\users\aka\miniconda3\envs\test01\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\test01\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
edit2: I forgot to mention that I installed Jupyter using pip.
to recreate the problem I did:
conda create -n env1
conda activate env1
pip install jupyter
jupyter --paths
config:
C:\Users\Aka.jupyter
c:\users\aka\miniconda3\envs\env1\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\env1\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
conda create --clone env1 -n env2
conda activate env2
jupyter --paths
config:
C:\Users\Aka.jupyter
c:\users\aka\miniconda3\envs\env1\etc\jupyter
C:\ProgramData\jupyter
data:
C:\Users\Aka\AppData\Roaming\jupyter
c:\users\aka\miniconda3\envs\env1\share\jupyter
C:\ProgramData\jupyter
runtime:
C:\Users\Aka\AppData\Roaming\jupyter\runtime
If I were to install jupyter with conda into a brand new environment and then clone the environment, jupyter behaves as expected. Note: I installed jupyter with pip because I am using python 3.5 because of other packages I need and installing jupyter with conda in my environments kept breaking it. I reached out to conda-forge for help but they said "sorry, we don't support python 3.5".
Jupyter only needs to be install in a single location - either a Conda env or at the system-level.
Jupyter installed in Conda env
To use other envs as kernels, one needs to install nb_conda_kernels in the env with Jupyter, and ipykernel in any env you wish to use as a kernel. Always launch jupyter notebook from the env with Jupyter and the others will be available automatically.
Jupyter outside Conda
If Jupyter is installed at a system level, one must manually register the Conda envs one wishes to use as kernels:
conda activate my_env
conda install ipykernel
python -m ipykernel install --user --name my_env_name
Then launch Jupyter from anywhere.

Jupyter Notebook's terminal command not using correct conda environment

I have 2 conda environments installed:
- env1: base environment where jupyter-notebook is installed and started from
- env2: project environment with ipykernel installed
I manually added kernelspecs for the 2 environments following this guide.
Everything works fine. sys.executable in 2 kernels show separate, correct paths. But for terminal commands (i.e. !which python), no matter which kernel I'm running in the environment defaults to env1.
Is there any way to have the notebook automatically change this to the kernel's environment?
P.S. I already tried installing nb_conda, nb_conda_kernels
install nb_conda and nb_conda_kernels into your base.
conda install nb_conda nb_conda_kernels -n env1
This should give you the ability to change kernel in jupyter, and use the env2 kernel.
I would install jupyter notebook in the base env (not env1, not env2)
Then install nb_conda_kernels in the base
in env1 and env2, install ipykernel
in env1 and env2, run this:
python -m ipykernel install --user --name env1 --display-name "env1 env"
Check this out for more info:
New Conda environment with latest Python Version for Jupyter Notebook

Installed librairies can't be imported in Jupyter Notebook

I've created a python 3.6 environment using the conda command. I have then activated that environment and installed a few librairies.
I then open a Jupyter Notebook in this environment using Anaconda Navigator and I am unable of importing graphviz, a librairie I have installed.
The name of the kernel on the top right is Python 3 and not the name of my environment.
How can I install librairies in my environment and then import them in Jupyter Notebook?
Thank you for any help
Code I ran to create my environment and install the librairies:
conda create -n myEnv pip python=3.6
activate myEnv
conda install -c conda-forge opencv
conda install -c conda-forge matplotlib

Categories

Resources