简体   繁体   中英

ModuleNotFoundError: No module named 'dotenv'

Facing dotenv not found error.

 % flask run
 * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

Error: While importing 'app', an ImportError was raised:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/cli.py", line 260, in locate_app
    __import__(module_name)
  File "/Users/tedx/cpt/python/pythonBackend/app.py", line 4, in <module>
    from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

My environment is setup as follow:

% dotenv --version
dotenv, version 0.20.0
% pip --version
pip 21.3.1 from /Users/tedx/.local/share/virtualenvs/pythonBackend-DMWtwxfH/lib/python3.6/site-packages/pip (python 3.6)
% python --version
Python 3.6.8
% pipenv --version
pipenv, version 2022.4.8

I have tried the answers to similar problem but still getting this error. Few things that I had tried are:

- pip uninstall python-dotenv
- pip install -U python-dotenv

Also pip freeze output shows python-dotenv .

% pip freeze                     
argcomplete==2.0.0
astroid==2.11.7
attrs==22.1.0
autograd==1.4
awscli==1.24.10
blinker==1.5
boto3==1.23.10
botocore==1.26.10
certifi==2022.6.15
cfn-flip==1.3.0
charset-normalizer==2.0.12
click==8.0.4
colorama==0.4.4
dataclasses==0.8
dill==0.3.4
docutils==0.16
durationpy==0.5
Flask==2.0.3
Flask-Cors==3.0.10
future==0.18.2
hjson==3.1.0
idna==3.3
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
isort==5.10.1
itsdangerous==2.0.1
Jinja2==3.0.3
jmespath==0.10.0
kappa==0.6.0
lazy-object-proxy==1.7.1
Lifetimes==0.11.3
mailjet-rest==1.3.4
MarkupSafe==2.0.1
mccabe==0.7.0
numpy==1.19.5
packaging==21.3
pandas==1.1.5
pep517==0.13.0
pip-tools==6.4.0
placebo==0.10.0
platformdirs==2.4.0
pluggy==1.0.0
py==1.11.0
pyasn1==0.4.8
pylint==2.13.9
PyMySQL==1.0.2
pytest==7.0.1
python-dateutil==2.8.2
*python-dotenv==0.20.0*
python-slugify==6.1.2
pytz==2022.2.1
PyYAML==6.0
requests==2.27.1
rsa==4.7.2
s3transfer==0.5.2
scipy==1.5.4
sentry-sdk==1.9.5
six==1.16.0
stripe==4.1.0
text-unidecode==1.3
toml==0.10.2
tomli==1.2.3
tqdm==4.64.0
troposphere==3.1.1
typed-ast==1.5.4
typing_extensions==4.1.1
urllib3==1.26.11
Werkzeug==2.0.3
wrapt==1.14.1
wsgi-request-logger==0.4.6
zappa==0.54.2
zipp==3.6.0 

Trying these and re-installing dotenv fixed this issue:

pip uninstall dotenv
pip uninstall python-dotenv
pip install python-dotenv

Also you may have dotenv installed at the system level (outside of your virtual environment). If yes, you could try uninstalling that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM