0

My Mac computer has Python 3.6 and Python 2.7 and I have successfully installed the basic modules such as numpy, scipy and matplotlib, for example, by doing the routine pip install and pip3 install. My Python 3.6 works totally well in Anaconda-Jupiter-Notebook, IDLE and Terminal, while Python 2.7 works only in terminal but not in IDLE.

Terminal - OK

enter image description here

Then for version check I tried

pip --version

Returning: pip 10.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip (python 2.7)

pip3 --version

Returning: pip 10.0.1 from /Users/son520804/anaconda3/lib/python3.6/site-packages/pip (python 3.6)

Then,

which python2

Returning: /Library/Frameworks/Python.framework/Versions/2.7/bin/python2

which pip2

Returning: /Library/Frameworks/Python.framework/Versions/2.7/bin/pip2

How could I resolve this issue and enable the Python 2.7 idle to import the modules? Much appreciated for your help.

son520804
  • 413
  • 5
  • 11
  • Try installing packages with setup.py. Here is how: https://stackoverflow.com/questions/1471994/what-is-setup-py – Armster Nov 20 '18 at 01:24

2 Answers2

1
find / -iname '*numpy*'

This is a terminal operation not a python command, you can try running that in the terminal to see where it's storing numpy, but you'll probably get the python3's version.

Try:

pip2 uninstall numpy

Then:

pip2 install numpy

It might be due to your machine seeing python3 as your default "python" so pip might actually be installing it again to python3. By denoting pip2 it should be linked to python2 (might actually need to do 'pip2.7'). Hope it helps!

Rrr
  • 102
  • 1
  • 2
  • 13
  • other than restarting the computer, using sudo pip install numpy, or restarting the IDLE, i'm not sure. Make sure to uninstall the modules as well and to reinstall them incase something went wrong. – Rrr Jun 05 '18 at 04:26
  • It turns out a weird problem...... Now I worked out partially that if I open the Python 2.7 IDLE first, and then open the file and run, it is now OK.. But if I click on open for that file, the same import error occurs. (WTF?) – son520804 Jun 05 '18 at 04:35
  • It probably has something to do with conflicting paths from anaconda/python2/python3. You should probably use virtual environments or use pyenv from here: https://github.com/pyenv/pyenv – Rrr Jun 05 '18 at 04:39
1

Perhaps your pip is an alias to pip3. Find it out by pip --version and if so install packages for python 2.7 as pip2.7 install matplotlib

Ilya
  • 183
  • 5
  • I also tried this and returned requirement already satisfied, but I still failed to import the module in IDLE. Something went wrong that I don't know. – son520804 Jun 05 '18 at 04:08