简体   繁体   English

我不断收到错误“ModuleNotFoundError:我的 settings.py 文件中没有名为‘environ’的模块”。 我已经在我的 python shell 中安装了依赖项

[英]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:由于以下原因,可能会出现此问题:

  1. You are using.您正在使用。 Virtual environment, but you installed module outside the virtual environment.虚拟环境,但是您在虚拟环境之外安装了模块。
  2. You haven't added 'environ', in your your settings.py file in INSTALLED_APPS您尚未在 INSTALLED_APPS 的 settings.py 文件中添加“环境”

Make sure you have done the following three actions:确保您已完成以下三个操作:

  1. Install the package through this command:通过以下命令安装 package:

    (inside venv) pip install django-environ

  2. Select the right python interpreter(the environment in which you have installed the package) Select 右 python 解释器(你安装包的环境)

  3. 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.

相关问题 不断收到错误消息:ModuleNotFoundError:当我安装了请求时,没有名为“请求”的模块 - keep getting error: ModuleNotFoundError: No module named 'requests' when i have requests installed 收到错误 ModuleNotFoundError: No module named 'mysql' 当我安装它时 - getting error ModuleNotFoundError: No module named 'mysql' when i have installed it 部署python Django项目到Heroku报错:ModuleNotFoundError: No module named '<settings.py folder name> '</settings.py> - Deploying python Django project to Heroku error: ModuleNotFoundError: No module named '<settings.py folder name>' 将 LoginBackEnd 模块导入 settings.py 时出错 - Getting error when I import LoginBackEnd module into settings.py 我在Django中的settings.py文件太长了。 如何将其分成两部分? - My settings.py file in Django is getting too long. How do I split it into two? 我已经在我的 django 项目中成功安装了 django 调试工具栏。 显示错误(ModuleNotFoundError: No module named 'debug_toolbarstore) - I have successfully installed django debug toolbar in my django project. Display error (ModuleNotFoundError: No module named 'debug_toolbarstore) 我不断收到此错误 ModuleNotFoundError: No module named &#39;template&#39; - I keep getting this error ModuleNotFoundError: No module named 'template' 如何获取未在我的 settings.py 文件中定义的 django 默认设置值? - How do I obtain django default settings values NOT defined in my settings.py file? 如何将我的settings.py文件中的常量导入到Django控制台中? - How do I import constants from my settings.py file into my Django console? python manage.py runserver 错误:ModuleNotFoundError:没有名为“settings”的模块 - python manage.py runserver error : ModuleNotFoundError: No module named 'settings'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM