我在这个python3 virtualenv中:
(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pyenv virtualenvs
3.7.3/envs/facenet_pytorch (created from /home/marco/.pyenv/versions/venv373)
3.7.3/envs/venv373 (created from /home/marco/.pyenv/versions/3.7.3)
* facenet_pytorch (created from /home/marco/.pyenv/versions/venv373)
venv373 (created from /home/marco/.pyenv/versions/3.7.3)
据我了解,所需的模块已经安装:
(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pip3 install facenet_pytorch
Requirement already satisfied: facenet_pytorch in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (2.2.8)
Requirement already satisfied: requests in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from facenet_pytorch) (2.23.0)
Requirement already satisfied: numpy in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from facenet_pytorch) (1.18.1)
Requirement already satisfied: chardet<4,>=3.0.2 in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from requests->facenet_pytorch) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from requests->facenet_pytorch) (2.9)
Requirement already satisfied: certifi>=2017.4.17 in /home/marco/.pyenv/versions/3.7.3
/envs/facenet_pytorch/lib/python3.7/site-packages (from requests->facenet_pytorch)
(2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/marco/.pyenv
/versions/3.7.3/envs/facenet_pytorch/lib/python3.7/site-packages (from
requests->facenet_pytorch) (1.25.8)
通过pip冻结,似乎确实安装在了virtualenv中:
(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ pip3 freeze --local
certifi==2019.11.28
chardet==3.0.4
facenet-pytorch==2.2.8
idna==2.9
numpy==1.18.1
requests==2.23.0
urllib3==1.25.8
但是当我尝试执行此单行代码时:
prova.py:
from facenet_pytorch import MTCNN
我收到ModuleNotFoundError:没有名为'facenet_pytorch'的模块
(base) marco@pc01:~/PyTorchMatters/facenet_pytorch/examples$ python3 prova.py
Traceback (most recent call last):
File "prova.py", line 1, in <module>
from facenet_pytorch import MTCNN
ModuleNotFoundError: No module named 'facenet_pytorch'
更新)已解决: 只需使用pip install(不是pip3)安装即可解决问题
马可