python - ModuleNotFoundError while module was installed using pip
问题描述
This is a very weird situation. I've been using django and venv for a while and during my last pull of code, when trying to run python manage.py collectstatic
, I ran into a ModuleNotFoundError. However, the module is installed and if I try to reinstall it, pip tells me I already have it.
The strange thing is I'm seeing importlib using my system python path ("/usr/lib/python3.6...") which I think it should be my virtualenv path...
If I run which python
I get the correct venv python path...
This is the error I get:
File "/home/ubuntu/venv/lib/python3.6/site-packages/django/apps/config.py",
line 90, in create
module = import_module(entry)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django-mailbox'
解决方案
您可能使用pip install django
. pip
这将安装与您的路径中找到的可执行文件相对应的 Python 安装模块。如果您安装了多个 Python 版本,则该pip
命令可能指向您的 Python 3.5 安装(例如),而该python
命令指向您的 Python 3.6 安装。
确保为正确的 Python 版本安装包,而不是:
pip install <package>
利用:
python -m pip install <package>
或者,如果您想使用特定的 Python 版本:
python3.6 -m pip install <package>
(在后一种情况下,您应该使用 运行您的应用程序python3.6 your_application.py
)
推荐阅读
- r - 在 shinyapps.io 中部署 R 应用程序 - 错误:HTTP 404
- mysql - 消除子查询中查询的行?
- mariadb - mariadb 用户定义的聚合函数
- php - 循环遍历数组并将值传递给mysql查询php
- php - 通过 date() 检测 PHP DST 已反转
- google-apps-script - Google 脚本 - 解压缩 Mimetype 应用程序/x-zip
- sql - 将三个不同查询中的数字相加
- python-3.x - 为什么我能够执行它显示运行 0 个测试
- go - 尝试在电子表格上执行 BatchUpdate 请求时获取“未定义:sheets.DeleteSheet”
- python - 可以存储在内存中的函数