Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

708
Views
no module named 'dotenv' python 3.8

EDIT: Solved, if anyone comes across this python3.8 -m pip install python-dotenv worked for me.

I've tried reinstalling both dotenv and python-dotenv but I'm still getting the same error. I do have the .env file in the same directory as this script.

#bot.py
import os
import discord

from dotenv import load_dotenv
load_dotenv()


token=os.getenv('DISCORD_TOKEN')

client = discord.Client()


@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')


client.run(token)
over 4 years ago · Santiago Trujillo
7 answers
Answer question

0

in your installation manager if it's Ubuntu or Debian try: apt install python3-dotenv

you can also try sudo pip3 install python-dotenv to install via pip.

Whatever you do remember to include explicitly the missing 3 part.

Debian/Ubuntu have separate packages and as of the present time python means python2 and python3 means python3 in their apt repositories. However, when it comes to your locally installed python binary on your system which python binary it defaults to using may vary depending on what /usr/bin/python is symlinked to on your system. Some systems it's symlinked to something like python2.7 and other's it may be something like python3.5. Similar issues exist with locally installed pip. Hence, why using the '3' is important when installing or searching for python packages

over 4 years ago · Santiago Trujillo Report

0

I'm new to Python and just got exact same error. Just changed install command to what I used from a MongoDB tutorial to install PyMongo. It worked like a charm :)

python -m pip install python-dotenv

over 4 years ago · Santiago Trujillo Report

0

This will solve just installing via terminal:

pip3 install python-dotenvfor python 3.0 versions or pip install python-dotenv for python different than 3.0

over 4 years ago · Santiago Trujillo Report

0

If you're using poetry (https://python-poetry.org), then...

Be sure you're doing:

$ poetry run SOME_COMMAND
# such as `poetry run pytest`

Instead of just:

$ SOME_COMMAND
# such as `pytest`

My problem (in detail) was...

# Starting with a _contrasting_ example that _unexpectedly worked_..

# A long time ago I did..

$ pip install pytest

# And now, I was doing everything below..

$ poetry add requests

# ..Then I wrote code that has `import requests` in it
# ..Then I wrote some unit test code (to use with pytest) to test the use of `requests`

# ..And NOT knowing I'm supposed to do `poetry run pytest`, I was just doing

$ pytest

# ..And it (oddly) worked, perhaps because maybe `requests` had been installed globally somewhere for me.

# ..But then I did

$ poetry add python-dotenv 

# ..Then I wrote code that had `from dotenv import load_dotenv` in it
# ..Then I wrote some unit test code (to use with pytest) to test the use of `python-dotenv`

# And I got the error I should have gotten..

$ pytest

# ..a bunch of error output, including..
ModuleNotFoundError: No module named 'dotenv'

Thus, the fix was:

# Get rid of the global pytest. Don't want to use that.
# (I think this step is optional, b/c I think `poetry run pytest` below will use the pytest installed via poetry in your virtual env (i.e. I _think_ it will (on it's own) NOT use the globally installed pytest.))
$ pip uninstall pytest

$ poetry add python-dotenv
$ poetry add --dev pytest

$ poetry run pytest

Credit for the fix goes to:

https://github.com/joeyespo/pytest-watch/issues/112

over 4 years ago · Santiago Trujillo Report

0

In my case, I was aliasing python to python3, in my zsh console.

Running a .py file with python3 -i filename.py made it work.

over 4 years ago · Santiago Trujillo Report

0

I had the same issue because I was running the installation command locally (in my virtual env).

When running it globally (outside of virtual env) it finally resolved the issue ;)

over 4 years ago · Santiago Trujillo Report

0

I had the same issue (Python 3.8.5, dotenv 0.15.0) and was getting ModuleNotFoundError: No module named 'dotenv' in both the console and JupyterLab. All other packages seemed to install via pip with no problems.

I just ran:

pip3 uninstall python-dotenv

pip3 install -U python-dotenv

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!