PIP表示已安装了软件包,但实际上没有

时间:2018-09-09 19:40:00

标签: python pip pycharm python-3.6

中,我只键入了pip install discord。如果我再次尝试(这样做),它的响应将如图所示。但是python表示未安装。 表示async def <name>():可以,在 没有 正确导入不和谐之前,它从未发生过(它会进行检查)。 PyCharm通常还会告诉我何时未安装模块。这不是昨天发生的,而是突然之间。

Screenshot 由于该机器人运行的服务器在脱机时会讨厌它,因此任何帮助将不胜感激。

编辑:

尝试@javajavs的答案后,它仍然在做同样的事情。除非这次说 已安装,即使它引发了ImportError

#2

编辑2:

我将在此处提供源代码以供参考:

import discord
import random
import Utilities as util
import sys

client = discord.Client()

logs = []

#global giveaway
#giveaway = util.giveaway.Giveaway()

cats = ["https://media.giphy.com/media/l3q2SKnzUMdELQkpi/giphy.gif", "https://media.giphy.com/media/TA6Fq1irTioFO/giphy.gif", "https://media.giphy.com/media/ORBjACSOzSYq4/giphy.gif", "https://giphy.com/gifs/cat-2QHLYZFJgjsFq?utm_source=media-link&utm_medium=landing&utm_campaign=Media%20Links&utm_term="]
@client.event
async def on_message(message):
  global logs#, giveaway
  message.content = str(message.content)
  if message.content.startswith("-pet"):
    await client.send_message(message.channel, "{0}, {1} is petting you! \n {2}".format("Catto", str("<@"+message.author.id+">"), random.choice(cats)))
  if message.author == client.user:
    return
  if str(message.author) == "#7136": # Admin Bot Commands
    if message.content.startswith("::stop"):
      for i in logs:
        await client.delete_message(i)
      client.close()
      sys.exit()
    elif message.content.startswith("::restart"):
      for i in logs:
        await client.delete_message(i)
      os.system("start src.py")
      client.close()
      sys.exit()

    if message.author == client.get_server("473895210762371072").get_member("269340844438454272"):
      if message.content.startswith("g-end"):
        await client.send_message(message.channel, "Congragulations, <@{0}>! You've won {1}!".format(giveaway.chooseWinner().id, giveaway.reward))
        giveaway.delete()
  if message.channel == client.get_channel("488097503128977458"):
    """if message.content.startswith("g-join"):
      if message.author not in giveaway.contestants:
        giveaway.contestantJoin(message.author)
        print("\n"*100)
        for i in giveaway.contestants:
          print(str(i))
      else:
        await client.send_message(message.author, "You cant enter more than once!!")
    """
    await client.delete_message(message)

@client.event
async def on_ready():
  global logs
  print("Started\n________________")
  logs.append(await client.send_message(client.get_channel("485891955717308436"), "`{0}`".format(util.initmsg)))
  """
  embed=discord.Embed(title="Giveaway!", description="Prize: {0}".format(giveaway.reward))
  embed.set_thumbnail(url="https://media.giphy.com/media/goGe7aJXfmEtW/giphy.gif")
  embed.add_field(name="Winners:", value=giveaway.winners, inline=True)
  embed.set_footer(text="Created by Hyper#7136")
  await client.send_message(client.get_channel("488097503128977458"), embed=embed)
  """
client.run("token")

编辑3:

因此,经过一会儿思考,我进入cmd并尝试从venv文件夹运行pip。

C:\Users\*****\>cd venv
C:\Users\*****\venv>cd Scripts
C:\Users\*****\venv\Scripts>pip3 install discord

它安装了..?我试图运行该程序,但引发了错误...

Traceback (most recent call last):
  File "C:/Users//Desktop/Spooper/src.py", line 1, in <module>
    import discord
  File "C:\Users\\venv\lib\site-packages\discord\__init__.py", line 20, in <module>
    from .client import Client, AppInfo, ChannelPermissions
  File "C:\Users\\venv\lib\site-packages\discord\client.py", line 38, in <module>
    from .state import ConnectionState
  File "C:\Users\\venv\lib\site-packages\discord\state.py", line 36, in <module>
    from . import utils, compat
  File "C:\Users\\venv\lib\site-packages\discord\compat.py", line 32
    create_task = asyncio.async
                              ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:5)

如果您使用的是pycharm创建的环境,则将discord.py下载到常规python文件夹中将无济于事,因为它们使用两种不同的python环境。转到设置>项目:>项目解释器,然后按屏幕右侧的绿色加号。现在,键入模块的名称(discord.py)并下载所需的模块。打申请。现在您已经安装了discord.py。

编辑:您安装了0.16版本。您可能要删除它并下载1.X.X版本,因为那是您似乎正在使用的版本。

编辑2:删除0.0.2不一致。它不应该在那里并且正在干扰导入过程。