Reputation: 1
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.
Upvotes: 0
Views: 101
Reputation: 111
Make sure the python path that you given in bashrc is correct. Also it will be good to use conda environment to try out the same since there is confusion in python environments. For that you can follow the below steps:
Create the environment and activate it using following commands:
conda create -n test_env python=2.7
conda activate test_env
conda install ipykernel
ipython kernel install --name test_env --user
Then install the required packages in the environment that you created and try to import it within the created environment.
Upvotes: 0