ImportError: No module named skimage

desmond13: <p>Hi, I am new to pythorch and I am trying to use it with virtualenvironment and a jupyter notebook, but all the time I start something new I seem to have many problems.</p>
<p>I am trying to follow <a href="https://pytorch.org/tutorials/beginner/data_loading_tutorial.html" rel="nofollow noopener">this</a> tutorial and when I import skimage I have the error:</p>
<p><code>ImportError: No module named skimage</code></p>
<p>I know I was missing the library in my virtualenvironment. Therefore I installed but this did not solve the problem.</p>
<p>Below the procedure I followed:</p>
<ol>
<li>Create the virtualenvironment from scratch<br>
<code>virtualenv -p /usr/bin/python2.7 pythorchTutorialsVenv</code>
</li>
<li>Install jupyter in the virtualenvironment<br>
<code>virtualenv -p /usr/bin/python2.7 pythorchTutorialsVenv</code>
</li>
<li>Activate the virtualenvironment I just created<br>
source pythorchTutorialsVenv/bin/activat</li>
<li>Start jupyter lab<br>
<code>jupyter lab</code>
</li>
<li>Run the notebook</li>
<li>Get the error</li>
<li>Install the scikit-image library with<br>
<code>python -m pip install scikit-image</code>
</li>
<li>Check that everything went well</li>
</ol>
<pre><code class="lang-auto">pip show scikit-image
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. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: scikit-image
Version: 0.14.5
Summary: Image processing routines for SciPy
Home-page: http://scikit-image.org
Author: None
Author-email: None
License: Modified BSD
Location: /home/schiano/pythorchTutorials/pythorchTutorialsVenv/lib/python2.7/site-packages
Requires: pillow, matplotlib, cloudpickle, scipy, six, networkx, PyWavelets
Required-by: 
</code></pre>
<p>After all this I restarted my kernel in jupyter lab but I still get the same error.</p>
<p>Anyone can help? Thanks!</p>

desmond13: <p>I found out the source of this problem. My virtualenvironment somehow uses the system python installation and not the one present in the virtualenvironment. I will need to understand how to solve this problem.</p>
<p>I know that this is not really related to pytorch but mostly to virtualenvironment.</p>

desmond13: <p>I solved my problem. How I did was the following:</p>
<p>Create the virtualenvironment<br>
<code>virtualenv -p python3 testenv1</code><br>
Now, from inside the environment install ipykernel using pip:<br>
<code>pip install ipykernel </code><br>
And now install a new kernel:<br>
<code>ipython kernel install --user --name=projectname</code></p>
<p>At this point, you can start jupyter, create a new notebook and select the kernel that lives inside your environment.</p>
<p>Start jupyter with</p>
<p><code>jupyter notebook</code></p>
<p>Then if I try to run this file:</p>
<hr>
<pre><code class="lang-auto">from __future__ import print_function, division 
! python --version 
! python2 --version 
! python3 --version 
import os 
import torch 
import pandas as pd 
from skimage import io, transform 
import numpy as np 
import matplotlib.pyplot as plt 
from torch.utils.data import Dataset, DataLoader 
import sys 
print(sys.version) 
</code></pre>
<p>I get all the errors of (module torch, pandas, skimage not found).</p>
<p>You can solve them by</p>
<p><code>python --m pip install torch </code><br>
<code>python --m pip install pandas </code><br>
<code>python --m pip install scikit-image </code></p>
<p>I got inspired by this blog post: <a href="https://anbasile.github.io/posts/2017-06-25-jupyter-venv/" rel="nofollow noopener">https://anbasile.github.io/posts/2017-06-25-jupyter-venv/</a></p>

reekjohns: <aside class="quote no-group" data-username="desmond13" data-post="1" data-topic="78947">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/47e85d/48.png" class="avatar"> desmond13:</div>
<blockquote>
<p>ImportError: No module named skimage</p>
</blockquote>
</aside>
<p>You need a file named <strong>init</strong>.py (two underscores on each side) in every folder in the hierarchy. This is what python looks for to know that it should access a particular folder. The files are meant to contain initialization instructions but even if you create them empty this will solve it. To get rid of this error “ImportError: No <a href="http://net-informations.com/ql/pya/modules.html" rel="noopener nofollow ugc">module</a> named”, you just need to create <strong>init</strong>.py in the appropriate directory and everything will work fine.</p>