Reputation: 413
I am doing Medical Image Analysis, in that I need package imageio
in jupyter notebook
. I am writing this command
!pip install imageio
Giving me error like this
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting imageio
Using cached imageio-2.9.0.tar.gz (3.3 MB)
ERROR: Package 'imageio' requires a different Python: 2.7.17 not in '>=3.5'
My kernel
Jupyter one set to Python3
!python3 --version
Python 3.6.3 :: Anaconda, Inc.
I tried
!pip3 install imageio
which correctly Installed it with this output
Requirement already satisfied: imageio in /home/jayakumars/anaconda3/envs/fastai2/lib/python3.6/site-packages (2.15.0)
Requirement already satisfied: numpy in /home/jayakumars/anaconda3/envs/fastai2/lib/python3.6/site-packages (from imageio) (1.19.5)
Requirement already satisfied: pillow>=8.3.2 in /home/jayakumars/anaconda3/envs/fastai2/lib/python3.6/site-packages (from imageio) (8.4.0)
But still when import
imageio
package
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
import glob
import nibabel as nib
import cv2
import imageio
from tqdm.notebook import tqdm
from ipywidgets import *
from PIL import Image
from fastai.basics import *
from fastai.vision.all import *
from fastai.data.transforms import *
Giving me ImportError
ImportError Traceback (most recent call last)
<ipython-input-40-9c1456a18eb5> in <module>()
6 import nibabel as nib
7 import cv2
----> 8 import imageio
9 from tqdm.notebook import tqdm
10 from ipywidgets import *
ImportError: No module named imageio
So, How can I install it?
I tried pip3
and I was expecting to remove imageio ``importError
Upvotes: 1
Views: 227
Reputation: 619
You are getting this error because Jupyter Notebook is installed for your system Python (/usr/bin/python
), not for your conda environment (/home/jayakumars/anaconda3/envs/fastai2/bin/python
). Therefore when you started Jupyter Notebook with jupyter notebook --no-browser --port=8878
, even though you had run conda activate fastai2
, it was still running the Jupyter Notebook installed for the global Python, and therefore your code was also running in the global python. You can check this by running import sys
and print(sys.executable)
.
To run your code inside the fastai2
environment, the easiest way at least is to install Jupyter Notebook inside the environment and run that. So run conda activate fastai2
and then inside the environment run pip install notebook
(or to be safe, /home/jayakumars/anaconda3/envs/fastai2/bin/pip install notebook
).
Then you should be able to run jupyter notebook --no-browser --port=8878
inside the env (or to be safe, /home/jayakumars/anaconda3/envs/fastai2/bin/jupyter notebook --no-browser --port=8878
). You can verify that your code is running in the environment with import sys
and print(sys.executable)
again.
Finally, you may need to install the packages you were using (numpy
, pandas
, matplotlib
, nibabel
, etc.) in the fastai2
environment, since they may not be installed yet. You can do this with pip install
in the environment (or to be safe, /home/jayakumars/anaconda3/envs/fastai2/bin/pip install
). You can also run these commands using !
from inside jupyter notebook.
Upvotes: 0