sm!ley 2023-10-03 16:53 采纳率: 0%
浏览 12

安装pygame时出现的一些问题

我在安装pygame时,他报了一大错,也没安上

报错:


```python
Traceback (most recent call last):
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 34, in global_tempdir_manager
    yield
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 571, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 144, in __exit__
    next(self.gen)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\operations\build\build_tracker.py", line 44, in get_build_tracker
    with contextlib.ExitStack() as ctx:
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 586, in __exit__
    raise exc_details[1]
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 571, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 156, in __exit__
    self.cleanup()
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 173, in cleanup
    rmtree(self._path)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 291, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 381, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 327, in iter
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 160, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 384, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\misc.py", line 128, in rmtree
    shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler)
TypeError: rmtree() got an unexpected keyword argument 'onexc'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 571, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 156, in __exit__
    self.cleanup()
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 173, in cleanup
    rmtree(self._path)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 291, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 381, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 327, in iter
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 160, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 384, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\misc.py", line 128, in rmtree
    shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler)
TypeError: rmtree() got an unexpected keyword argument 'onexc'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 571, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 156, in __exit__
    self.cleanup()
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 173, in cleanup
    rmtree(self._path)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 291, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 381, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 327, in iter
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 160, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 384, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\misc.py", line 128, in rmtree
    shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler)
TypeError: rmtree() got an unexpected keyword argument 'onexc'
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Scripts\pip.exe\__main__.py", line 7, in <module>
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\cli\main.py", line 79, in main
    return command.main(cmd_args)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\cli\base_command.py", line 100, in main
    with self.main_context():
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 144, in __exit__
    next(self.gen)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\cli\command_context.py", line 19, in main_context
    with self._main_context:
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 586, in __exit__
    raise exc_details[1]
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 571, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(value)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 31, in global_tempdir_manager
    with ExitStack() as stack:
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 586, in __exit__
    raise exc_details[1]
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\contextlib.py", line 571, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 156, in __exit__
    self.cleanup()
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\temp_dir.py", line 173, in cleanup
    rmtree(self._path)
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 291, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 381, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 327, in iter
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 160, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_vendor\tenacity\__init__.py", line 384, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\86180\AppData\Local\Programs\Python\Python312-32\Lib\site-packages\pip\_internal\utils\misc.py", line 128, in rmtree
    shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler)
TypeError: rmtree() got an unexpected keyword argument 'onexc'

```

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-10-03 18:16
    关注

    【相关推荐】



    • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7744153
    • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:【Pygame实战】嗷大喵历险记之程序员吸猫指南:真的太上头了~
    • 您还可以看一下 程序员学院老师的Python专项训练 巩固语法+数据分析+商城开发课程中的 Pygame开发实战之搭建主框架小节, 巩固相关知识点
    • 除此之外, 这篇博客: 使用pygame实现的五子棋,状态机, 估值函数中的 不那么重要的类,但对于这个五子棋来说,就是核心类 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

      这里放一个大概,后面会给出全部代码

      GameEntity的子类

      # 棋子类
      class Chessman(GameEntity):
          def __init__(self, world, image):
              GameEntity.__init__(self, world, "Chessman", image)
      

      棋盘局势 <- 整个棋盘的局势走向

      # 棋盘局势
      class ChessBoxSituations(object):
          def __init__(self, size=(19, 19)):
              self.size = size
              self.situations = {}		#棋盘局势(棋子在棋盘的点集)
              self.last_drop_position = (0, 0)
              self.current_drop_player = 0
              self.count = 0
      
          # 局势发展(棋子增加)
          def evolve(self, chessman_point, owner):
              self.situations[chessman_point] = owner
              self.last_drop_position = chessman_point
              self.count += 1
      
          # 获取棋盘某点坐标的状态
          def get_state(self, point):
              px, py = point
              x, y = self.size
              if x - px < 0 or y - py < 0 or x - px >= 19 or y - py >= 19:
                  return self.OutOfRange()
              if point not in self.situations:
                  return None
              return self.situations[point]
      
          class OutOfRange(object):
              pass
      

      对战的AI

      附:

      # 八个方向 N:北, E:东, S:南, W:西
      D_N = Vector2(0, -1)
      D_EN = Vector2(1, -1)
      D_E = Vector2(1, 0)
      D_ES = Vector2(1, 1)
      D_S = Vector2(0, 1)
      D_WS = Vector2(-1, 1)
      D_W = Vector2(-1, 0)
      D_WN = Vector2(-1, -1)
      DIRECTION = (D_N, D_EN, D_E, D_ES, D_S, D_WS, D_W, D_WN)
      
      # 智能体棋手类
      class PlayerAgent(GameEntity):
          def __init__(self, world, box_situations, chess_image, no=1, opponent=0):
              GameEntity.__init__(self, world, "PlayerAgent")
              self.no = no	#自己
              self.opponent = opponent	#对手
              self.box_situations = box_situations
              self.chess_image = chess_image
              self.drop_points = []	# 可选的将要下的棋子位点
              self.points_weight = 0	# drop_points里的点的权重(里面所有点权重相同)
              wait_state = PlayerAgentStateWait(self)
              drop_state = PlayerAgentStateDrop(self)
              self.brain.add_state(drop_state)
              self.brain.add_state(wait_state)
      
          # 更新下棋点集
          def update_drop_points(self, location, weight):
              if self.points_weight < weight:
                  self.drop_points.clear()
                  self.drop_points.append(location)
                  self.points_weight = weight
      
              elif self.points_weight == weight:
                  self.drop_points.append(location)
      
          # 决策(获取下棋位置)
          def decision_making(self):
              self.points_weight = 0
              self.drop_points.clear()
              filter_point = []
      
              # 棋盘上所有的有棋子的点
              for point in self.box_situations.situations:
      
                  # 获取该点的相邻八个点的空位点
                  for DIR in DIRECTION:
                      cur_point = point+DIR
                      x, y = cur_point
                      if self.box_situations.get_state((x, y)) is None:
                          if cur_point in filter_point:
                              continue
                          weight = self.evaluate(cur_point, self.no) + self.evaluate(cur_point, self.opponent)
                          self.update_drop_points((x, y), weight)
                          filter_point.append(cur_point)
      
              print("权重:", self.points_weight)
              print(self.drop_points)
      
              # 棋盘为空,棋盘为满
              if len(self.drop_points) == 0:
                  return 10, 10
              return self.drop_points[randint(0, len(self.drop_points) - 1)]
      
          # 估值
          def evaluate(self, point, no):
              value = 0
      		#......
      		#此处省略n行代码
      		#......
              return value
      
          # 下棋
          def drop(self, point):
              index_x, index_y = point
              destination_x = index_x * 30.25
              destination_y = index_y * 30.2 - 15
      	
          	# 棋盘上该点没有棋子
              if (index_x, index_y) not in self.box_situations.situations:
                  chess = Chessman(self.world, self.chess_image)
                  chess.location = (destination_x, destination_y)
                  self.world.add_entity(chess)
                  self.box_situations.evolve(point, self.no)
                  self.box_situations.current_drop_player = self.opponent
      

      emmm、、、、、

      规则设计的一个简单的智能体,主要在对局中对局部点价值的判断,然后综合起来后选择权重最高的点来下。
      如何判断一个点的权重:evaluate()
      在棋盘上,一个点有八个方向,横竖左斜右斜。下棋时候,就会先估算在这八个方向上的总价值是多少。
      栗子(没有看错,也没有写错,就是栗子):点一在这里可以形成五子,那么价值就是300000,点二只能形成活四,那么这个点的价值就是3000。所以电脑在判断完所有的点后,会选出一个价值最大的点下。

      五子棋的一些术语:活四,活三,活二,死四,死三,死二
      附:
      在这里插入图片描述

      继承State类

      # 智能体等待状态
      class PlayerAgentStateWait(State):
          def __init__(self, player_agent):
              State.__init__(self, "PlayerAgentWait")
              self.player_agent = player_agent
      
          def check_conditions(self):
              if self.player_agent.world.is_over:
                  return None
              if self.player_agent.world.playing and \
                      self.player_agent.box_situations.current_drop_player == self.player_agent.no:
                  return "PlayerAgentDrop"
              return None
      

      继承State类

      # 智能体下棋状态
      class PlayerAgentStateDrop(State):
          def __init__(self, player_agent):
              State.__init__(self, "PlayerAgentDrop")
              self.player_agent = player_agent
              self.drop_point = None
      
          def do_actions(self):
      
              if self.drop_point is not None:
                  self.player_agent.drop(self.drop_point)
      
          def check_conditions(self):
              if self.player_agent.box_situations.current_drop_player == self.player_agent.opponent:
                  return "PlayerAgentWait"
              return None
      
          def entry_actions(self):
              self.DecisionMakingThread(self).start()
      
          class DecisionMakingThread(threading.Thread):
              def __init__(self, owner):
                  threading.Thread.__init__(self)
                  self.owner = owner
      
              def run(self):
                  self.owner.drop_point = self.owner.player_agent.decision_making()
      
          def exit_actions(self):
              self.drop_point = None
      

      它超脱于世界了~ ) _ )~
      还有,感觉有点重复了。。。。

      # 玩家
      class Player(object):
          def __init__(self, world, box_situations, chess_image, no=0, opponent=1):
              self.world = world
              self.box_situations = box_situations
              self.chess_image = chess_image
              self.no = no
              self.opponent = opponent
      
          # 下棋
          def drop(self, location):
              # 同上智能体类
      

      胜负在手,天下我有
      注:被托管的可怜娃

      # 裁判员
      class Adjudicator(GameEntity):
          def __init__(self, world, box_situations):
              GameEntity.__init__(self, world, "Adjudicator")
              self.box_situations = box_situations
              self.win_image = pygame.image.load(WIN).convert()
              self.lose_image = pygame.image.load(LOSE).convert()
              self.winner = None	# 赢家
              self.current_time = 0
              self.update_time = -1
      
          def process(self, time_passed):
              # 游戏结束
              if self.world.is_over:
                  # 游戏结束,等待3秒显示结果
                  if self.update_time > self.current_time:
                      self.current_time += time_passed
                      return
      
                  # 移除棋盘的棋子, 清空局势
                  for entity in list(self.world.entities.values()):
                      if entity.name is "Chessman":
                          self.world.remove_entity(entity)
                  self.box_situations.situations.clear()
                  self.box_situations.count = 0
      
                  if self.winner == 0:
                      self.image = self.win_image
                  elif self.winner == 1:
                      self.image = self.lose_image
      
                  if self.winner is not None:
                      w, h = SCREEN_SIZE
                      self.location = (w / 3, h / 2)
                      self.winner = None
      
              else:
                  # 是否有胜负
                  winner = self.win_or_lose()
                  if winner is not None or self.box_situations.count == 361:
                      self.world.is_over = True
                      self.winner = winner
                      # 得出胜负,在3秒后更新显示胜负视图
                      self.update_time += 3
                  else:
                      # 没有胜负不显示胜负视图
                      self.image = None
      
          def win_or_lose(self):
      		#....
      

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 10月3日

悬赏问题

  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?