Python: Installed a local package with pip3, but got module not found error

送分小仙女□ 提交于 2020-06-25 10:29:04

问题


Procedure:

  • I strictly followed the instructions here: https://python-packaging.readthedocs.io/en/latest/minimal.html
  • Except that I used the pip3 install -e .

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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/50643068/python-installed-a-local-package-with-pip3-but-got-module-not-found-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!