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
Related
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.
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
I'm pretty new to python, Jupyter notebook, Tensorflow, and that whole lot in general. I'm getting started with a machine learning project. I've gotten to the point where I want to import "nltk" into my thing. It doesn't work. I've installed nltk with pip, and conda, and everything, in my terminal. When I do it again in the notebook, it says I've already installed it, which is correct. But when I try to import it it gives me a ModuleNotFoundError:
I'm on a macbook, by the way. Any help?
Going forward you can follow these steps (through terminal) so that same issues don't crop up again.
Create a conda environment if it's not already done
conda create -n py3_env python=3.8
Get into the conda environment
conda activate py3_env
Install ipykernel
conda install ipykernel
Link the kernel to this conda env
ipython kernel install --user --name=py3_env
Deactivate the conda environment
conda deactivate
Now, when you open jupyter, you can select this kernel from the dropdown menu kernel >> Change kernel. Now, all the packages you've installed in this conda environment would be available in jupyter as well. E.g. you can install nltk in this environment in the following way:
conda activate py3_env
pip install nltk
conda deactivate
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.
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