9

Procedure:

Error:

It still can not find the module:

python3
Python 3.6.5 (default, Apr 25 2018, 14:26:36)
import funniest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'funniest'

However, when I import the module in python, it CAN find it:

python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
import funniest

My python:

sys.executable
'/usr/local/opt/python/bin/python3.6'

Question

Why pip3 installed it for python 2.7 not for my python 3.x ?

Thanks!

Maximillian Laumeister
  • 19,884
  • 8
  • 59
  • 78
askmeasku
  • 273
  • 1
  • 3
  • 11
  • What does `pip3 --version` return? – hoefling Jun 01 '18 at 12:12
  • It returns: ```pip3 --version pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)``` But why? – askmeasku Jun 01 '18 at 13:50
  • 1
    Looks like a wrong symlink - what does `ls $(which pip3)` return? – hoefling Jun 01 '18 at 14:17
  • ```> ls $(which pip3) /usr/local/bin/pip3*``` Some week ago I used ```brew``` for an upgrade (not sure if it is python), then it messed my python up, I guess. – askmeasku Jun 02 '18 at 22:28
  • Hi @hoefling, seems that I need to change the shebang line, as mentioned here: https://stackoverflow.com/questions/31407208/pip3-4-v-refers-to-python2-7-installation – askmeasku Jun 02 '18 at 22:35

2 Answers2

13

Following the hint from @hoefling, I found that my pip3 is somewhat linked to a wrong python version.

Then install with python3 -m pip install worked.

askmeasku
  • 273
  • 1
  • 3
  • 11
4

I suggest that you use a virtual environment, to get around all this hassle.

If you make a virtual environment with python3, there is no ambiguity of python versions, and life is much simpler.

Use the command

pip install --upgrade virtualenv

and then, depending on where your python3 is residing (you can check by typing which python3 on the terminal), you should do something like this next:

virtualenv -p /usr/bin/python3 mypy3
source mypy3/bin/activate

your terminal will show (mypy3) in the beginning of the line (before the prompt) at this point. Here, you can do:

pip install funniest

Another way is to use virtualenvwrapper , which I find very convenient.

Look at the documentation or the relevant parts of this tutorial if you wish to know more. But make sure you create an environment with python3 alone, so that there is no confusion.

loudmummer
  • 544
  • 3
  • 19