没有名为“dotenv”python3.8的模块

编辑:解决了,如果有人遇到这个python3.8-m pip install python-dotenv为我工作。

编辑:解决了,如果有人遇到这个python3.8 -m pip install python-dotenv为我工作。

我已经尝试重新安装 dotenv 和 python-dotenv,但我仍然收到同样的错误。

#bot.py
import os
import discord
from dotenv import load_dotenv
load_dotenv()
token=os.getenv('DISCORD_TOKEN')
client = discord.()
@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')
client.run(token)
45

我是 Python 的新手,只是得到了完全相同的错误。只是将 install 命令更改为我从 MongoDB 教程中用来安装 PyMongo 的。它的工作就像一个魅力:)

python -m pip install python-dotenv
25

如果是 Ubuntu 或 Debian,请在安装管理器中尝试:apt install python3-dotenv

您也可以尝试sudo pip3 install dotenv通过 pip 安装。

无论您做什么,都要记住明确包含缺少的3部分。

因此,类似的 Debian / Ubuntu 有单独的软件包,并且目前python意味着python2python3意味着python3在其 apt 存储库中。但是,当涉及到您的系统上本地安装的python二进制文件时,它默认使用的/ bin / symthon

4

这将解决只是通过终端安装:

pip3 install python-dotenv适用于 python 3.0 版本或pip install python-dotenv适用于不同于 3.0 的 python

2

如果您使用的是poetry(https://python-poetry.org),那么...

确保你正在做:

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

而不仅仅是:

$ SOME_COMMAND
# such as `pytest`

我的问题(详细)是...

# 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'

因此,修复是:

# 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

修复的功劳归于:

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

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(134)
MATLAB导入文件的最大大小应该是多少
上一篇
使用QT5.12.3从源代码构建vlc-qt时出错
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(59条)