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.
I am trying to follow this tutorial and when I import skimage I have the error:
ImportError: No module named skimage
I know I was missing the library in my virtualenvironment. Therefore I installed but this did not solve the problem.
Below the procedure I followed:
Create the virtualenvironment from scratch virtualenv -p /usr/bin/python2.7 pythorchTutorialsVenv
Install jupyter in the virtualenvironment virtualenv -p /usr/bin/python2.7 pythorchTutorialsVenv
Activate the virtualenvironment I just created
source pythorchTutorialsVenv/bin/activat
Start jupyter lab jupyter lab
Run the notebook
Get the error
Install the scikit-image library with python -m pip install scikit-image
Check that everything went well
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:
After all this I restarted my kernel in jupyter lab but I still get the same error.
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.
I know that this is not really related to pytorch but mostly to virtualenvironment.
Create the virtualenvironment virtualenv -p python3 testenv1
Now, from inside the environment install ipykernel using pip: pip install ipykernel
And now install a new kernel: ipython kernel install --user --name=projectname
At this point, you can start jupyter, create a new notebook and select the kernel that lives inside your environment.
Start jupyter with
jupyter notebook
Then if I try to run this file:
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)
I get all the errors of (module torch, pandas, skimage not found).
You need a file named init.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 module named”, you just need to create init.py in the appropriate directory and everything will work fine.