"No module named matplotlib" error in Jupiter Notebook - python

I open my anaconda virtual environment in this way (Linux)
source /home/sasha/anaconda3/bin/activate
conda activate gl-env (gl-env is my virtual environment)
pip3 install jupyter notebook
pip3 install matplotlib
pip3 install -U turicreate
jupyter notebook
After launching Jupiter, i see "No module named matplotlib" mistake, while turicreate is working normally.
How can i solve this problem?

You should not use pip with Anaconda. Use conda instead. So you commands should have been:
conda install jupitor notebook
conda install matplotlib
conda install turicreate
You can check conda for the -U option.

Related

ModuleNotFoundError in jupyter notebook when importing a module after conda install

I'm trying to use conda to set up one of my projects. I installed openCV by conda install -c conda-forge opencv. When I run conda list, I can see openCV in the list. Running python -i and then import cv2 works, but when I open up Jupyter Notebook and navigate to that folder (I have to do it this way because running jupyter notebook in the directory also pulls up an error), and open up a notebook which imports cv2, I get an error. Why is this happening, and how would I solve it? Any kind of help will be greatly appreciated.
So as I said before, I wasn't able to start Jupyter Notebook from the command line, I had to start it from the start menu and navigate to my folder. Because of that, my notebook wasn't working in the conda environment that I created. I fixed that by running python -m ipykernal install --user --name <env_name> --display-name "<display_name>". I had to conda install ipykernel. It works now. Thanks for the other answers.
Usually that indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check sys.executable to see which Python it's running in, and sys.path to see where it's looking for imports
Everybody says that pip installing from notebook is not the best practice, but maybe for a fast try it would do the thing:
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} packagename
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install packagename
I used it from Install python packages on Jupyter Notebook and it worked for me.
Step 1: Activate environment before running
conda activate <environment-name>
Step 2: Install ipykernel
conda install -c anaconda ipykernel
Step 3: Add the conda environment to ipykernel
ipython kernel install --name <environment-name> --user
Step 4: Install your package
conda install -c conda-forge opencv
References:
How to add your Conda environment to your jupyter notebook in just 4 steps
Conda environments not showing up in Jupyter Notebook

Can't install installed python packages

I am using Jupyter Notebook to install packages with the command: !pip install.
I just used this command to install the Options package, but it's still not showing up. I checked the default python Environment as well as the conda environment.
list of Python environments
To install packages into jupyter notebook you have to use conda instead of pip. Just find the conda install instruction for the package you are trying to install.
For example, the command to install numpy on conda is:
conda install -c anaconda numpy
instead of the regular pip version which would've been:
pip install numpy
You can search for yours by googling: conda install <package-name-you-want-to-install>.

One conda environment automatically takes other's dependencies in jupyter notebook

I have two conda environments named 'myenv' and 'newenv' and i installed tensorflow in myenv but not in newenv and in both environment i installed ipykernel using:
pip install ipykernel
and then :
python -m ipykernel install --user --name name_env --display-name "Python (name_env)"
I did this in both environment so that now i have 3 kernels in my jupyter notebook named: Python(myenv),Python(newenv),Python3 .
But when changed to kernel newenv and try to import tensorflow and it imports however i haven't installed tensorflow in newenv but when i tried to import it through comand terminal of newenv it shows error 'No module named tensorflow'.
Then why it imports in jupyter notebook not in command terminal?
Please help me to solve this issue.

Tensorflow is not importing on jupyter notebook

I have installed tensorflow on my linux desktop and I have tried importing it in the terminal which worked. But when I tried the same thing on jupyter notebook, I am getting the error:
ModuleNotFoundError: No module named 'tensorflow'
To install tensorflow I have followed below steps:
conda create -n tensorflow_env python=3
source activate tensorflow_env
pip install tensorflow
Please install your conda environment using the below command in terminal
python -m ipykernel install --user --name tensorflow_env.
After installation,
1)reload your jupyter notebook.
2)In jupyter notebook, click on kernel->change kernel->tensorflow_env.
3)open new notebook with kernel "tensorflow_env"
4)Try importing tensorflow.

jupyter cannot find my conda env

I have a conda env in this directory in my mac
/anaconda/envs/dl
then I start my conda env by activate source dl
and when I start the jupyter it does not show the conda env dl, and only shows that its using python3 but not the conda env.
Notebook python3
And if I click terminal it shows this.
You need to install nb_conda, however, at the moment nb-conda cannot be directly installed with python3.6.
A way around that is to install it from conda-forge:
conda install -c conda-forge nb_conda
And also do not forget to install jupyter notebook on the new environment.
Install nb_conda , it should work.
To use jupyter notebook inside a virtual environment, ipykernal is required to be installed in your venv.
Inside your virtual environment:
pip install ipykernel
Then run the kernel "self-install" script:
python -m ipykernel install --user --name=my-virtualenv-name
Now, your new kernel has been installed.

Categories