[英]I keep getting the error "ModuleNotFoundError: No module named 'environ' in my settings.py file". I have installed the dependency in my python shell
I keep getting an import error on environ in my settings.py file, I have it installed via poetry in my.venv file as well.我在我的 settings.py 文件中不断收到关于 environ 的导入错误,我也通过 my.venv 文件中的诗歌安装了它。 Could this be an error outside the settings file possibly?
这可能是设置文件之外的错误吗?
`
import environ
env = environ.Env(
DEBUG=(bool, False),
ENVIORNMENT=(str, 'PRODUCTION'),
)
environ.Env.read_env()
ENVIRONMENT= env.str('ENVIRONMENT')
SECRET_KEY = env.str('SECRET_KEY')
DEBUG = env.bool('DEBUG')
ALLOWED_HOSTS = tuple(env.list('ALLOWED_HOSTS'))
`
Make sure that you are using the desired python interpreter, that your virtualenv is setup correctly , and that the desired django-environ is installed within that virtualenv via确保您使用的是所需的 python 解释器,您的virtualenv 设置正确,并且所需的 django-environ 安装在该 virtualenv 中
(inside venv) pip install django-environ
The problem could occur due to the following reasons:由于以下原因,可能会出现此问题:
Make sure you have done the following three actions:确保您已完成以下三个操作:
Install the package through this command:通过以下命令安装 package:
(inside venv) pip install django-environ
Select the right python interpreter(the environment in which you have installed the package) Select 右 python 解释器(你安装包的环境)
Create an ".env" file in project root directory.在项目根目录中创建一个“.env”文件。 And based on its reference doc here , it should be consisting of something like below:
根据其参考文档here ,它应该由以下内容组成:
DEBUG=on
SECRET_KEY=your-secret-key
DATABASE_URL=psql://user:un-githubbedpassword@127.0.0.1:8458/database
SQLITE_URL=sqlite:///my-local-sqlite.db
CACHE_URL=memcache://127.0.0.1:11211,127.0.0.1:11212,127.0.0.1:11213
REDIS_URL=rediscache://127.0.0.1:6379/1?client_class=django_redis.client.DefaultClient&password=ungithubbed-secret
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.