调试此类问题的方法是首先确定您使用的是哪个python 和哪个pip。然后,其次,查看您安装模块的位置以及 Python 查找不匹配项的位置。
所以,如果你使用命令python 来启动 Python,你会运行这个:
type python
如果你使用命令python3 来启动 Python,你会运行这个:
type python3
现在根据您的使用对pip 或pip3 运行相同的命令:
type pip # or "type pip3"
现在看看你运行的是什么版本的python 和pip:
python -V # or "python3 -V" if you use "python3"
pip -V # or "pip3 -V" if you use "pip3"
您现在应该知道您正在使用哪些版本的工具。
现在看看pip(或pip3,如果你使用它)安装你的pyPyrTools:
pip show pyPyrTools # or "pip3 show pyPyrTools" if you use "pip3"
样本输出
Name: pyPyrTools
Version: 0.2.3
Summary: Python tools for multi-scale image processing, including Laplacian pyramids, Wavelets, and Steerable Pyramids
Home-page: https://github.com/LabForComputationalVision/pyPyrTools
Author: Eero Simoncelli, Rob Young, and William F. Broderick
Author-email: eero.simoncelli@nyu.edu
License: MIT
Location: /usr/local/lib/python3.7/site-packages
Requires: Pillow, numpy, matplotlib, scipy
Required-by:
特别重要的是倒数第三行的Location: 字段。
现在检查您的 Python 实际在哪里寻找模块:
python3 -c "import sys; print(sys.path)" # or "python -c ..." if you use "python" rather than "python3"
样本输出
['', '/Users/mark/StackOverflow', '/Users/mark/OpenCV/lib/python3.7/site-packages', '/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/mark/Library/Python/3.7/lib/python/site-packages', '/usr/local/lib/python3.7/site-packages']
因此,我的答案上一部分中的Location:必须在此处列出,以便 Python 找到 pyPyrTools。如果不是,您要么使用与 python 不匹配的 pip 进行安装,要么未正确配置 PYTHONPATH。
如果您运行上述命令,请在您的问题下单击edit 并将输出粘贴到那里 - 不要在难以格式化和阅读的评论中。