Flask Application Not Running Properly: Issues with Environment and Dependencies specifically dotenv

77 views Asked by At

Issues:

When I run flask run, I get an error:

from dotnev import load_dotenv, dotenv_values
ModuleNotFoundError: No module named 'dotnev'.

I'm unable to import the dotenv module: Import "dotenv" could not be resolved Pylance (reportMissingImports).

Steps Taken:

    Recreated the virtual environment.
    Verified package versions in the virtual environment. using pip freeze. It has been found "python-dotenv==1.0.0"
    Checked the Flask application structure.
    Ensured correct usage of .env and .env.secret files.
    Used python-dotenv to load environment variables.
    Tried different interpreters for python, it causees a mess and doesn't fix it

Pieces of code:

    from dotenv import load_dotenv, dotenv_values


    config = dotenv_values("env.secret")

Installed packages:

    bcrypt==4.0.1
    blinker==1.6.3
    cffi==1.16.0
    click==8.1.7
    colorama==0.4.6
    cryptography==41.0.5
    Flask==3.0.0
    itsdangerous==2.1.2
    Jinja2==3.1.2
    MarkupSafe==2.1.3
    pycparser==2.21
    PyMySQL==1.1.0
    python-decouple==3.8
    python-dotenv==1.0.0
    setuptools==68.2.2
    Werkzeug==3.0.1

Any help would be greatly appreciated. I am hoping that dotenv can work one way or another.

Here is the file structure

project_folder

    pycache
    node_modules
    static
    templates
    venv
    .envsecret
    app.py
    launch.json
    package-lock.json
    package.json
    Readme.txt
    settings.json
    test.py
1

There are 1 answers

0
Spam Corn On

I have no idea what fixed it but it started working. I rebooted the machine a couple of times. Didn't work on the project for awhile. Switched python interpreters a couple of times. Checked the locations of python, flask, and dotenv. I am very puzzled.