Jon*_*hai 19 python import module
编辑:解决了,如果有人遇到这python3.8 -m pip install python-dotenv对我有用。
我已经尝试重新安装 dotenv 和 python-dotenv,但我仍然遇到相同的错误。我确实在与此脚本相同的目录中有 .env 文件。
#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)
Run Code Online (Sandbox Code Playgroud)
LFM*_*ekz 14
如果是 Ubuntu 或 Debian,请在您的安装管理器中尝试:
apt install python3-dotenv
您也可以尝试sudo pip3 install python-dotenv通过pip安装。
无论您做什么,都记得明确包含缺少的3部分。
于Debian / Ubuntu具有单独的包并作为当前时间的python装置python2和python3方法python3在其易于储存库。但是,当涉及到python系统上本地安装的二进制文件时,它默认使用的 python 二进制文件可能会有所不同,具体取决于 /usr/bin/python 在系统上的符号链接。有些系统符号链接到类似的东西,python2.7而其他系统则可能是类似的东西python3.5。本地安装的pip. 因此,为什么在安装或搜索 python 包时使用“3”很重要
Tie*_* Do 14
我是 Python 新手,刚遇到完全相同的错误。刚刚将安装命令更改为我从 MongoDB 教程中使用的命令来安装 PyMongo。它就像一个魅力:)
python -m pip install python-dotenv
The*_*ick 10
这将解决仅通过终端安装的问题:
pip3 install python-dotenv对于 python 3.0 版本或pip install python-dotenv对于不同于 3.0 的 python
小智 6
poetry(https://python-poetry.org),那么...确保你正在做:
$ poetry run SOME_COMMAND
# such as `poetry run pytest`
Run Code Online (Sandbox Code Playgroud)
而不仅仅是:
$ SOME_COMMAND
# such as `pytest`
Run Code Online (Sandbox Code Playgroud)
# 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'
Run Code Online (Sandbox Code Playgroud)
# 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
Run Code Online (Sandbox Code Playgroud)
修复归功于:
https://github.com/joeyespo/pytest-watch/issues/112
| 归档时间: |
|
| 查看次数: |
40606 次 |
| 最近记录: |