小编Jan*_*ski的帖子

Google 应用程序引擎部署失败 - 查找“pip”的模块规范时出错(AttributeError:模块“__main__”没有属性“__file__”)

我们使用命令提示符c:\gcloud app deploy app.yaml,但出现以下错误:

Running "python3 -m pip install --requirement requirements.txt --upgrade --upgrade-strategy only-if-needed --no-warn-script-location --no-warn-conflicts --force-reinstall --no-compile (PIP_CACHE_DIR=/layers/google.python.pip/pipcache PIP_DISABLE_PIP_VERSION_CHECK=1)"
Step #2 - "build": /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": Done "python3 -m pip install --requirement requirements.txt --upgr..." (34.49892ms)
Step #2 - "build": Failure: (ID: 0ea8a540) /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine google-app-engine-python

18
推荐指数
2
解决办法
2112
查看次数

async_generator' 对象不可迭代

我需要在异步函数中返回一个值。我尝试使用同步形式的返回:

import asyncio

async def main():
    for i in range(10):
        return i
        await asyncio.sleep(1)

print(asyncio.run(main()))
Run Code Online (Sandbox Code Playgroud)

输出:

0 [Finished in 204ms]

但它只是返回第一个循环的值,而不是expexted。于是将代码修改如下:

import asyncio

async def main():
    for i in range(10):
        yield i
        await asyncio.sleep(1)

for _ in main():
    print(_)
Run Code Online (Sandbox Code Playgroud)

输出:

TypeError: 'async_generator' object is not iterable

通过使用异步生成器我面临这个错误。如何为异步函数的每个循环返回一个值?

谢谢

python async-await python-asyncio

10
推荐指数
1
解决办法
2万
查看次数

Pathlib和stem - Attributerror

作为代码的一部分,我的功能如下:

def match_output(orig_path: Path,lines: Iterable[str],stem: str, delim: str,delim_pred: Callable[[int], bool],) -> Iterable:
    n = 0
    path = orig_path.with_stem(f'{orig_path.stem}_{stem}')

    with path.open('w') as f:
        for line in lines:
            n_delim = line.count(delim)
            matched = delim_pred(n_delim)
            if matched:
                f.write(line)

            n += int(matched)
            yield

    logger.info(f'Number of {stem} lines: {n}')
Run Code Online (Sandbox Code Playgroud)

但是,我遇到属性错误,无法解决,请问有什么建议吗?

Traceback (most recent call last):
  File "C:/Users/HAXY8W/Desktop/pieter_code_rewriting/main.py", line 95, in <module>
    main()
  File "C:/Users/HAXY8W/Desktop/pieter_code_rewriting/main.py", line 88, in main
    process(
  File "C:/Users/HAXY8W/Desktop/pieter_code_rewriting/main.py", line 82, in process
    for n_lines, _ in enumerate(zip(*iters)):
  File "C:/Users/HAXY8W/Desktop/pieter_code_rewriting/main.py", line 27, in …
Run Code Online (Sandbox Code Playgroud)

python pathlib

3
推荐指数
1
解决办法
3659
查看次数

Ursina 中的 FirstPersonController 问题

我正在使用 Ursina 引擎创建 3D 游戏。然而,当我尝试加载 FirstPersonCharacter 时,我得到的只是一个灰色背景(正常)和一个位于中心的非常小的洋红色正方形,倾斜角度为 45\xc2\xb0。那是什么 ?

\n

我首先尝试为第一人称角色制作自己的机制,根据鼠标位置移动相机(我有这个),我正在玩数学和运动的东西......我正在看这个视频(https ://www.youtube.com/watch?v=DHSRaVeQxIk)完全是别的东西,我发现了 FirstPersonController。

\n

但是,使用与他(几乎)相同的代码,它不起作用!这是什么问题,有人遇到过吗?FirstPersonController 坏了吗?还是我脑子坏了?

\n

编辑:在 ursina 备忘单中发现,洋红色的小倾斜方块是光标。但我还是动不了,没有重力什么的?我看不到我的地板。

\n

第二次编辑:使用 ursina 备忘单提供的一些代码进行安排,我现在可以看到我的楼层。但我只能在 1 个轴上移动相机(上下),我无法移动,没有重力,什么都没有......

\n

这是我的代码:

\n
from ursina import *\nfrom ursina.prefabs.first_person_controller import FirstPersonController\n\napp = Ursina()\n\nwindow.title = \'The lab\'\nwindow.borderless = False\nwindow.fullscreen = True\nwindow.exit_button.visible = False\nwindow.fps_counter.enabled = True\n\nfloorcubes = []\nfor i in range(-20, 20, 2):\n    for j in range(-20, 20, 2):\n        floorcubes.append(Entity(model=\'cube\', color=color.white, scale=(2,2,2), position = (i, 0, j)))\nplayer = FirstPersonController()\napp.run()\n
Run Code Online (Sandbox Code Playgroud)\n

这是 ursina 备忘单中提供的代码,稍作安排:

\n
from …
Run Code Online (Sandbox Code Playgroud)

python ursina

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