Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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'))

`
like image 867
Corey Marchand Avatar asked Aug 20 '20 19:08

Corey Marchand


People also ask

What is modulenotfounderror in Python?

A ModuleNotFoundError is raised when Python cannot successfully import a module. The full error message looks something like this: ModuleNotFoundError: No module named 'your_module_name' This error is encountered when you forget to install a dependency for a project.

Why is my Python module not installed in Python?

Python module is not Installed You can get the issue when you are trying to import a module of a library which not installed in your virtual environment. So before importing a library’s module, you need to install it with the pip command. Let’s import an module (requests) into app.py file which is not installed into our virtual environment:

Why am I getting modulenotfounderror-no module named'dedupe'?

Maybe your python3 is try to find your script's module in the " /usr/local/lib/python3.x " directory . So if that module is not there then the ModuleNotFoundError: No module named 'dedupe' error is happening .

What is no module named your_module_name?

ModuleNotFoundError: No module named 'your_module_name' This error is encountered when you forget to install a dependency for a project. Because you haven’t installed the dependency, Python does not know where to locate it. ModuleNotFoundErrors come up in user-defined modules.


2 Answers

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

(inside venv) pip install django-environ
like image 159
joe.dinius Avatar answered Nov 14 '22 22:11

joe.dinius


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.(based on its reference exceptionally not required for this package!)
like image 26
Prabhjot Singh Avatar answered Nov 14 '22 22:11

Prabhjot Singh