Getting ImportError while import numpy on Anaconda Jupyter Notebook but numpy already installed. Any solution? - anaconda

I ran same program before. But don't know suddenly it's showing ImportError. I did not change anything in Anaconda. Then what's going wrong ?

If you get a numpy import error, the C-libraries are not on the path. This means that you conda environment isn't activated.
To use conda environments in Jupyter follow this instuction:
How to add your Conda environment to your jupyter notebook in just 4 steps
On a side note: Why are you trying to mix pip and conda installs? This is asking for trouble!

Related

difference between conda install and pip install in jupyter notebook

I'm a little confused with package install in anaconda environment.
I can install my python packagse in the following ways.
open anaconda prompt and do : conda install tensorflow
launch an jupyter notebook from anaconda prompt, choose the default python kernel, and do:
!pip install tensorflow
Can someone tell me what is the difference between these two cases? Where are the python packages installed? What happens when I pip install python packages in default kernel in jupyter notebook?
I was able to install tensorflow in jupyter notebook in default kernel (python3), but trying to import tensorflow give me module note found error. Does anyone know why that happened? What is happening under the hood? Very much appreciate any help to clarification.
pip is the default package manager that ships with python. Conda is also a package manager, but it is third party. Conda was made especially for data science libraries. Libraries installed with conda usually give much better performance than pip. In pip, the packages are stored in python/scripts and conda stores them at /anaconda/pkgs/. As for the module not found error. I would need more information about it, but you can check out this video. I learnt how to install TensorFlow here and would highly recommend it.

ModuleNotFoundError: No module named 'mpl_toolkits.basemap'

I have trouble importing the basemap module of mpl_toolkits in python.
I've got following error message when I try to run "from mpl_toolkits.basemap import Basemap":
ModuleNotFoundError: No module named 'mpl_toolkits.basemap'
I'm using python 3.6.5 in windows.
I've found relevant Q&A in
"Python basemap module impossible to import" and I already followed what's instructed there (i.e. source activate MyProfileName, conda install basemap) but it didn't work.
The clue might already be given in the Q&A above but as I'm quite new to python, I couldn't figure out the solution.
I would recommend installing Anaconda environment from scratch. Let Anaconda handle dependencies for you. Then you need to install mpl_toolkits separately in your conda environment with:
conda install -c conda-forge basemap-data-hires
See also here.
After doing this, executing
from mpl_toolkits.basemap import Basemap
from python console should work normally.
I recently faced this problem on Windows 10. I had created a conda environment with python 3.7 and anaconda 5.2.0 and tried all retrieved solutions. But nothing worked for me and all my efforts worth many hours were in vain.
What I observed that currently Basemap is not compatible with python 3.0, so I remove the environment and creates a fresh with python 2.7 and anaconda 5.2.0. So, to help others who are juggling with same problem, here is the complete set of solution:
Getting the Basemap Toolkit (support the functionality of mapping data)
create conda environment as:
conda create -n Basemap python=2.7 anaconda=5.2.0
Activate the created conda environment:
activate Basemap
Install the following packages:
conda install -c conda-forge basemap
(do not use basemap=1.1.0, channel error comes "package basemap =1.1.0 is not
available from current channels")
"Only the 'crude' and 'low' resolution datasets are installed by default". You may
need to install the following for high resolution:
conda install -c conda-forge basemap-data-hires
PROJ is a generic coordinate transformation software that transforms geospatial
coordinates from one coordinate reference system (CRS) to another. This includes
cartographic projections as well as geodetic transformations.
conda install -c conda-forge proj4 </b>
(Better to avoid pro4=5.2.0 as specific packages generates error)
PROJ is a generic coordinate transformation software that transforms geospatial
coordinates from one coordinate reference system (CRS) to another. This includes
cartographic projections as well as geodetic transformations.
After installation of the Basemap toolkit, open the jupyter notebook a fresh, it should show the current environment in upper right corner.
To check the current environment in jupyter, type:
import sys
print(sys.executable)
If still the activated environment is not shown then:
run the following command in anaconda prompt in activated environment Basemap:
python -m ipykernel install --user --name Basemap --display-name "Python (Basemap)"
Now change the environment from Kernel-> change kernel -> Python (Basemap)
Finally Python(Basemap) should be shown in upper right corner.
Following needs to be imported in your program then to use it:
from mpl_toolkits.basemap import Basemap
In case of error: "No module named 'mpl_toolkits.basemap" type the following in jupyter:
import os
os.environ['PROJ_LIB'] = r'C:\ProgramData\Anaconda3\pkgs\proj4-5.2.0-h6538335_1006\Library\share
After this you need to restart apps for them to pick up the change, including explorer.exe. Restarting the machine is reccomended (but not required).
All the best. I hope this will work for you as well.

StopIteration: Could not import PIL.Image. The use of `array_to_img` requires PIL error

import keras
Using TensorFlow backend.
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'E:/Python/A-
Z/Convolutional_Neural_Networks/dataset/training_set',
target_size=(64, 64),
batch_size=32,
class_mode='binary')
test_set = test_datagen.flow_from_directory(
'E:/Python/A-
Z/Convolutional_Neural_Networks/dataset/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='binary')
classifier.fit_generator(
training_set,
steps_per_epoch=8000,
epochs=25,
validation_data=test_set,
validation_steps=2000)
please help I am a beginner in this CNN I am using keras to program the task but I am getting the above error(given in the title)
I have tried installing and then uninstalling pillow
but nothing working it is showing the same error I have also tried some other StackOverflow answers but they are also not working
I came the same error as you.
this is my environment:
I create "tensorflow" env in anaconda, python 3.6 kernel,activate the env, then
pip install tensorflow
pip install keras
pip install pillow
and the error was fixed.
I had the same problem. If you are using Anaconda and the Jupyter notebook this is what worked for me.
Close your notebook and stop Jupyter.
Exit out of your environment
Restart the environment again and run:
pip install pillow
and then:
pip install jupyterlab
and start jupyter-notebook back up and then add or (re-run):
from PIL import Image
In your notebook and hopefully .fit_generator will no longer throw that error.
The following is applicable to Windows users working with Anaconda:
If you've installed 'tensorflow' with pip, or a pip variant (ie. pip3), then you will have to install tensorflow again, but this time with the command conda install tensorflow.

Not able to get Python 2 environment in Jupyter Notebook after creating and activating in Anaconda Prompt

Working on my Windows machine, I installed Anaconda 3 and created a Python 2 environment in Anaconda Prompt using commands below:
conda create -n py2 python=2
activate py2
conda install numpy matplotlib pandas scikit-learn
However, when I run jupyter notebook in Anaconda Prompt, in the opened notebook, I checked Python version using this:
import sys
print('Python version is:', sys.version_info)
I found out it is Python 3 instead of Python 2...I wonder what's going on?
It turns out I need to install jupyter notebook like below in Anaconda Prompt as well, otherwise, the default Python 3 version notebook will be called.
conda install jupyter notebook
Now, if we launch jupyter notebook again, we'll get Python 2.
You may also find that you need to install the Notebook extensions which provides Conda environment and package access extension from within Jupyter Notebook. You can do that by running:
conda install nb_conda

FAIL: pandas in python3 jupyter notebook

My apologies in advance - I have read through multiple sites and tried multiple things, but am still having trouble.
On OSX. Am trying to execute "import pandas as pd" in a jupyter notebook with Python 3, but receive the following message:
ModuleNotFoundError: No module named 'pandas'
I created a new conda environment
conda create -n py3x python=3
activated it
source activate py3x
then opened jupyter
jupyter notebook
Did not work.
Tried this, but that seemed to default to Python 2: ImportError: No module named 'pandas'
I've also tried (perhaps?) every iteration from the following: Using both Python 2.x and Python 3.x in IPython Notebook
I have python 3 in jupyter notebook now, but none of the packages from anaconda. I also tried updating Anaconda (had already done Anaconda3 graphical install)
conda update anaconda
And that just said "All requested packages already installed"
Any further thoughts on terminal command lines to help would be much appreciated.

Resources