Previously I installed pytorch,PIL,numpy... using pip. After that I installed python3. Thus ipython switched from python2 to python3. I have to use ipython2 to start python2 kernel. These modules still works well in ipython2, but when I run a python script using python, python2, python2.7, they all raise ImportError:
ImportError: No module named PIL(numpy,torch...)
When run this command: sudo pip install numpy
return:
Requirement already satisfied: numpy in /usr/local/lib/python3.5/dist-packages (1.15.1)
when running this command: sudo pip2 install numpy
return: Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages
When I run: python, import sys, sys.path
it shows :
['', '/home/szy/miniconda2/lib/python27.zip', '/home/szy/miniconda2/lib/python2.7', '/home/szy/miniconda2/lib/python2.7/plat-linux2', '/home/szy/miniconda2/lib/python2.7/lib-tk', '/home/szy/miniconda2/lib/python2.7/lib-old', '/home/szy/miniconda2/lib/python2.7/lib-dynload', '/home/szy/.local/lib/python2.7/site-packages', '/home/szy/miniconda2/lib/python2.7/site-packages']
The location of numpy is not among them. and the sys.path in ipython2:
['', '/usr/local/bin', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/szy/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/IPython/extensions', '/home/szy/.ipython']
What's wrong? Previous I could run scripts with python and import these modules.