小编F.M*_*F.M的帖子

Linux 中的环境变量未使用 load_dotenv() 加载

我正在尝试制作一个不和谐的机器人,当我尝试使用 load_dotenv() 加载 .env 时,它不起作用,因为它说

Traceback (most recent call last):
  File "/home/fanjin/Documents/Python Projects/Discord Bot/bot.py", line 15, in <module>
    client.run(TOKEN)
  File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 708, in run
    return future.result()
  File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 687, in runner
    await self.start(*args, **kwargs)
  File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 650, in start
    await self.login(*args, bot=bot)
  File "/home/fanjin/.local/lib/python3.8/site-packages/discord/client.py", line 499, in login
    await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip
Run Code Online (Sandbox Code Playgroud)

这是我的机器人代码:

import os

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')

client = discord.Client()

@client.event
async def …
Run Code Online (Sandbox Code Playgroud)

python linux environment-variables dotenv

11
推荐指数
3
解决办法
4万
查看次数

错误:命令出错,退出状态为 1:python setup.py egg_info 检查日志以获取完整的命令输出。尝试安装 dotenv 时

我正在尝试为我的不和谐机器人安装 dotenv,pip3 install dotenv但它一直给我这个错误:

   ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xmobtpdk/dotenv/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xmobtpdk/dotenv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-xmobtpdk/dotenv/pip-egg-info
         cwd: /tmp/pip-install-xmobtpdk/dotenv/
    Complete output (51 lines):
        ERROR: Command errored out with exit status 1:
         command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-wheel-ts7a2idz/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-wheel-ts7a2idz/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-vsx7w_h3
             cwd: /tmp/pip-wheel-ts7a2idz/distribute/
        Complete output (15 lines):
        Traceback (most recent call last):
          File "<string>", line …
Run Code Online (Sandbox Code Playgroud)

python pip package dotenv

8
推荐指数
1
解决办法
4062
查看次数

标签 统计

dotenv ×2

python ×2

environment-variables ×1

linux ×1

package ×1

pip ×1