了解特定的Python列表理解

时间:2019-01-27 18:35:51

标签: python python-3.x generator list-comprehension

在给定骰子数量和边数的情况下,我尝试使用此代码来产生骰子掷骰的所有可能结果。该代码有效(但我不太了解列表理解的工作原理。

def dice_rolls(dice, sides):
   """
   Equivalent to list(itertools.product(range(1,7), repeat=n)) except
   for returning a list of lists instead of a list of tuples.
   """
   result = [[]]
   print([range(1, sides + 1)] * dice)
   for pool in [range(1, sides + 1)] * dice:
      result = [x + [y] for x in result for y in pool]
   return result

因此,我正在尝试重新编写列表理解

result = [x + [y] for x in result for y in pool]

进入FOR循环以尝试了解其工作方式,但目前无法正确执行。当前失败的代码:

for x in result:
   for y in pool:
      result = [x + [y]]

第二个问题:如果我想把它变成一个生成器(如果你有足够的骰子和边,因为这个函数是一个记忆猪),我只是在生产时就简单地产生列表中的每个项目而不是抛出它进入结果列表?

编辑:我想出了一种方法,可以在收到好评后将列表理解分解为循环,并希望捕获它:

def dice_rolls(dice, sides):
result = [[]]
for pool in [range(1, sides + 1)] * dice:
    temp_result = []
    for existing_values in result:  # existing_value same as x in list comp.
        for new_values in pool:  # new_value same as y in list comp.
            temp_result.append(existing_values + [new_values])
    result = temp_result
return result

2 个答案:

答案 0 :(得分:1)

我对这个问题的第一本能(通常是列表理解)是使用递归。尽管您已经请求了LOOPS,但这是令人惊讶的挑战。

这是我想出的;

def dice_rollsj(dice, sides):
    result = [[]]

    for num_dice in range(dice):
        temp_result = []
        for possible_new_values in range(1, sides+1):
            for existing_values in result:
                new_tuple = existing_values + [possible_new_values]
                temp_result.append(new_tuple)
        result = temp_result

我认为您会得到相同的正确答案,但是数字的排列顺序会有所不同。这可能是由于将值附加到列表的方式所致。我不知道。...请告诉我这是否有帮助。

我试图添加尽可能多的行,因为目标是扩展并理解理解。

答案 1 :(得分:0)

您正在~$ pip3 install -U --user 'mujoco-py<1.50.2,>=1.50.1' Collecting mujoco-py<1.50.2,>=1.50.1 Using cached https://files.pythonhosted.org/packages/cf/8c/64e0630b3d450244feef0688d90eab2448631e40ba6bdbd90a70b84898e7/mujoco-py-1.50.1.68.tar.gz Requirement already satisfied, skipping upgrade: Cython>=0.27.2 in ./.local/lib/python3.7/site-packages (from mujoco-py<1.50.2,>=1.50.1) (0.29.3) Requirement already satisfied, skipping upgrade: cffi>=1.10 in ./.local/lib/python3.7/site-packages (from mujoco-py<1.50.2,>=1.50.1) (1.11.5) Requirement already satisfied, skipping upgrade: glfw>=1.4.0 in ./.local/lib/python3.7/site-packages (from mujoco-py<1.50.2,>=1.50.1) (1.7.0) Requirement already satisfied, skipping upgrade: imageio>=2.1.2 in ./.local/lib/python3.7/site-packages (from mujoco-py<1.50.2,>=1.50.1) (2.4.1) Requirement already satisfied, skipping upgrade: lockfile>=0.12.2 in ./.local/lib/python3.7/site-packages (from mujoco-py<1.50.2,>=1.50.1) (0.12.2) Requirement already satisfied, skipping upgrade: numpy>=1.11 in ./.local/lib/python3.7/site-packages (from mujoco-py<1.50.2,>=1.50.1) (1.16.0) Requirement already satisfied, skipping upgrade: pycparser in ./.local/lib/python3.7/site-packages (from cffi>=1.10->mujoco-py<1.50.2,>=1.50.1) (2.19) Requirement already satisfied, skipping upgrade: pillow in /usr/lib/python3/dist-packages (from imageio>=2.1.2->mujoco-py<1.50.2,>=1.50.1) (5.1.0) Building wheels for collected packages: mujoco-py Building wheel for mujoco-py (setup.py) ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-z3t4vdud/mujoco-py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-49u4_yeg --python-tag cp37: running bdist_wheel running build Removing old mujoco_py cext /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/cymj_1.50.1.68_37_linuxcpuextensionbuilder_37.so Compiling /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.pyx because it changed. [1/1] Cythonizing /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.pyx warning: mujoco_py/generated/../pxd/mjmodel.pxd:99:4: 'mjtDisableBit' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:114:4: 'mjtEnableBit' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:121:4: 'mjtJoint' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:127:4: 'mjtGeom' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:149:4: 'mjtCamLight' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:157:4: 'mjtTexture' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:163:4: 'mjtIntegrator' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:168:4: 'mjtCollision' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:174:4: 'mjtCone' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:179:4: 'mjtJacobian' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:185:4: 'mjtSolver' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:191:4: 'mjtImp' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:198:4: 'mjtRef' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:203:4: 'mjtEq' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:211:4: 'mjtWrap' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:220:4: 'mjtTrn' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:230:4: 'mjtDyn' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:237:4: 'mjtGain' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:242:4: 'mjtBias' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:248:4: 'mjtObj' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:274:4: 'mjtConstraint' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:285:4: 'mjtConstraintState' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:294:4: 'mjtSensor' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:338:4: 'mjtStage' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:345:4: 'mjtDataType' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:99:4: 'mjtDisableBit' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:114:4: 'mjtEnableBit' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:121:4: 'mjtJoint' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:127:4: 'mjtGeom' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:149:4: 'mjtCamLight' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:157:4: 'mjtTexture' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:163:4: 'mjtIntegrator' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:168:4: 'mjtCollision' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:174:4: 'mjtCone' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:179:4: 'mjtJacobian' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:185:4: 'mjtSolver' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:191:4: 'mjtImp' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:198:4: 'mjtRef' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:203:4: 'mjtEq' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:211:4: 'mjtWrap' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:220:4: 'mjtTrn' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:230:4: 'mjtDyn' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:237:4: 'mjtGain' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:242:4: 'mjtBias' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:248:4: 'mjtObj' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:274:4: 'mjtConstraint' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:285:4: 'mjtConstraintState' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:294:4: 'mjtSensor' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:338:4: 'mjtStage' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:345:4: 'mjtDataType' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:75:4: 'mjtNum' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:77:10: 'mjPI' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:78:10: 'mjMAXVAL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:79:10: 'mjMINMU' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:80:10: 'mjMINIMP' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:81:10: 'mjMAXIMP' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:82:10: 'mjMAXCONPAIR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:83:10: 'mjMAXVFS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:84:10: 'mjMAXVFSNAME' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:87:10: 'mjNEQDATA' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:88:10: 'mjNDYN' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:89:10: 'mjNGAIN' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:90:10: 'mjNBIAS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:91:10: 'mjNREF' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:92:10: 'mjNIMP' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:93:10: 'mjNSOLVER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:96:4: 'mjtByte' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:100:8: 'mjDSBL_CONSTRAINT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:101:8: 'mjDSBL_EQUALITY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:102:8: 'mjDSBL_FRICTIONLOSS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:103:8: 'mjDSBL_LIMIT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:104:8: 'mjDSBL_CONTACT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:105:8: 'mjDSBL_PASSIVE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:106:8: 'mjDSBL_GRAVITY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:107:8: 'mjDSBL_CLAMPCTRL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:108:8: 'mjDSBL_WARMSTART' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:109:8: 'mjDSBL_FILTERPARENT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:110:8: 'mjDSBL_ACTUATION' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:111:8: 'mjDSBL_REFSAFE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:112:10: 'mjNDISABLE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:115:8: 'mjENBL_OVERRIDE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:116:8: 'mjENBL_ENERGY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:117:8: 'mjENBL_FWDINV' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:118:8: 'mjENBL_SENSORNOISE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:119:10: 'mjNENABLE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:122:8: 'mjJNT_FREE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:123:8: 'mjJNT_BALL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:124:8: 'mjJNT_SLIDE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:125:8: 'mjJNT_HINGE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:129:8: 'mjGEOM_PLANE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:130:8: 'mjGEOM_HFIELD' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:131:8: 'mjGEOM_SPHERE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:132:8: 'mjGEOM_CAPSULE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:133:8: 'mjGEOM_ELLIPSOID' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:134:8: 'mjGEOM_CYLINDER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:135:8: 'mjGEOM_BOX' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:136:8: 'mjGEOM_MESH' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:138:8: 'mjNGEOMTYPES' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:141:8: 'mjGEOM_ARROW' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:142:8: 'mjGEOM_ARROW1' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:143:8: 'mjGEOM_ARROW2' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:144:8: 'mjGEOM_LABEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:146:8: 'mjGEOM_NONE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:150:8: 'mjCAMLIGHT_FIXED' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:151:8: 'mjCAMLIGHT_TRACK' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:152:8: 'mjCAMLIGHT_TRACKCOM' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:153:8: 'mjCAMLIGHT_TARGETBODY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:154:8: 'mjCAMLIGHT_TARGETBODYCOM' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:158:8: 'mjTEXTURE_2D' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:159:8: 'mjTEXTURE_CUBE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:160:8: 'mjTEXTURE_SKYBOX' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:164:8: 'mjINT_EULER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:165:8: 'mjINT_RK4' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:169:8: 'mjCOL_ALL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:170:8: 'mjCOL_PAIR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:171:8: 'mjCOL_DYNAMIC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:175:8: 'mjCONE_PYRAMIDAL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:176:8: 'mjCONE_ELLIPTIC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:180:8: 'mjJAC_DENSE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:181:8: 'mjJAC_SPARSE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:182:8: 'mjJAC_AUTO' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:186:8: 'mjSOL_PGS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:187:8: 'mjSOL_CG' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:188:8: 'mjSOL_NEWTON' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:192:8: 'mjIMP_CONSTANT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:193:8: 'mjIMP_SIGMOID' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:194:8: 'mjIMP_LINEAR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:195:8: 'mjIMP_USER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:199:8: 'mjREF_SPRING' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:200:8: 'mjREF_USER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:204:8: 'mjEQ_CONNECT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:205:8: 'mjEQ_WELD' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:206:8: 'mjEQ_JOINT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:207:8: 'mjEQ_TENDON' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:208:8: 'mjEQ_DISTANCE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:212:8: 'mjWRAP_NONE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:213:8: 'mjWRAP_JOINT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:214:8: 'mjWRAP_PULLEY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:215:8: 'mjWRAP_SITE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:216:8: 'mjWRAP_SPHERE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:217:8: 'mjWRAP_CYLINDER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:221:8: 'mjTRN_JOINT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:222:8: 'mjTRN_JOINTINPARENT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:223:8: 'mjTRN_SLIDERCRANK' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:224:8: 'mjTRN_TENDON' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:225:8: 'mjTRN_SITE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:227:8: 'mjTRN_UNDEFINED' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:231:8: 'mjDYN_NONE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:232:8: 'mjDYN_INTEGRATOR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:233:8: 'mjDYN_FILTER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:234:8: 'mjDYN_USER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:238:8: 'mjGAIN_FIXED' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:239:8: 'mjGAIN_USER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:243:8: 'mjBIAS_NONE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:244:8: 'mjBIAS_AFFINE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:245:8: 'mjBIAS_USER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:249:8: 'mjOBJ_UNKNOWN' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:250:8: 'mjOBJ_BODY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:251:8: 'mjOBJ_XBODY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:252:8: 'mjOBJ_JOINT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:253:8: 'mjOBJ_DOF' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:254:8: 'mjOBJ_GEOM' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:255:8: 'mjOBJ_SITE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:256:8: 'mjOBJ_CAMERA' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:257:8: 'mjOBJ_LIGHT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:258:8: 'mjOBJ_MESH' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:259:8: 'mjOBJ_HFIELD' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:260:8: 'mjOBJ_TEXTURE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:261:8: 'mjOBJ_MATERIAL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:262:8: 'mjOBJ_PAIR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:263:8: 'mjOBJ_EXCLUDE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:264:8: 'mjOBJ_EQUALITY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:265:8: 'mjOBJ_TENDON' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:266:8: 'mjOBJ_ACTUATOR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:267:8: 'mjOBJ_SENSOR' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:268:8: 'mjOBJ_NUMERIC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:269:8: 'mjOBJ_TEXT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:270:8: 'mjOBJ_TUPLE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:271:8: 'mjOBJ_KEY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:275:8: 'mjCNSTR_EQUALITY' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:276:8: 'mjCNSTR_FRICTION_DOF' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:277:8: 'mjCNSTR_FRICTION_TENDON' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:278:8: 'mjCNSTR_LIMIT_JOINT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:279:8: 'mjCNSTR_LIMIT_TENDON' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:280:8: 'mjCNSTR_CONTACT_FRICTIONLESS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:281:8: 'mjCNSTR_CONTACT_PYRAMIDAL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:282:8: 'mjCNSTR_CONTACT_ELLIPTIC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:286:8: 'mjCNSTRSTATE_SATISFIED' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:287:8: 'mjCNSTRSTATE_QUADRATIC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:288:8: 'mjCNSTRSTATE_LINEARNEG' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:289:8: 'mjCNSTRSTATE_LINEARPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:290:8: 'mjCNSTRSTATE_CONE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:296:8: 'mjSENS_TOUCH' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:297:8: 'mjSENS_ACCELEROMETER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:298:8: 'mjSENS_VELOCIMETER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:299:8: 'mjSENS_GYRO' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:300:8: 'mjSENS_FORCE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:301:8: 'mjSENS_TORQUE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:302:8: 'mjSENS_MAGNETOMETER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:303:8: 'mjSENS_RANGEFINDER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:306:8: 'mjSENS_JOINTPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:307:8: 'mjSENS_JOINTVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:308:8: 'mjSENS_TENDONPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:309:8: 'mjSENS_TENDONVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:310:8: 'mjSENS_ACTUATORPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:311:8: 'mjSENS_ACTUATORVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:306:8: 'mjSENS_JOINTPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:307:8: 'mjSENS_JOINTVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:308:8: 'mjSENS_TENDONPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:309:8: 'mjSENS_TENDONVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:310:8: 'mjSENS_ACTUATORPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:311:8: 'mjSENS_ACTUATORVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:312:8: 'mjSENS_ACTUATORFRC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:315:8: 'mjSENS_BALLQUAT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:316:8: 'mjSENS_BALLANGVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:319:8: 'mjSENS_FRAMEPOS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:320:8: 'mjSENS_FRAMEQUAT' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:321:8: 'mjSENS_FRAMEXAXIS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:322:8: 'mjSENS_FRAMEYAXIS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:323:8: 'mjSENS_FRAMEZAXIS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:324:8: 'mjSENS_FRAMELINVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:325:8: 'mjSENS_FRAMEANGVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:326:8: 'mjSENS_FRAMELINACC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:327:8: 'mjSENS_FRAMEANGACC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:330:8: 'mjSENS_SUBTREECOM' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:331:8: 'mjSENS_SUBTREELINVEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:332:8: 'mjSENS_SUBTREEANGMOM' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:335:8: 'mjSENS_USER' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:339:8: 'mjSTAGE_NONE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:340:8: 'mjSTAGE_POS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:341:8: 'mjSTAGE_VEL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:342:8: 'mjSTAGE_ACC' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:346:8: 'mjDATATYPE_REAL' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:347:8: 'mjDATATYPE_POSITIVE' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:348:8: 'mjDATATYPE_AXIS' redeclared warning: mujoco_py/generated/../pxd/mjmodel.pxd:349:8: 'mjDATATYPE_QUAT' redeclared running build_ext building 'mujoco_py.cymj' extension creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7 creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp/pip-install-z3t4vdud creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp/pip-install-z3t4vdud/mujoco-py creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py creating /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/gl x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Imujoco_py -I/tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py -I/home/imran/.mujoco/mjpro150/include -I/home/imran/.local/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -c /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.c -o /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.o -fopenmp -w /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.c:53:10: fatal error: Python.h: No such file or directory #include "Python.h" ^~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for mujoco-py Running setup.py clean for mujoco-py Failed to build mujoco-py Installing collected packages: mujoco-py Running setup.py install for mujoco-py ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-z3t4vdud/mujoco-py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-t_1q5w6p/install-record.txt --single-version-externally-managed --compile --user --prefix=: running install running build Removing old mujoco_py cext /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/cymj_1.50.1.68_37_linuxcpuextensionbuilder_37.so running build_ext building 'mujoco_py.cymj' extension x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Imujoco_py -I/tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py -I/home/imran/.mujoco/mjpro150/include -I/home/imran/.local/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -c /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.c -o /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/generated/_pyxbld_1.50.1.68_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.o -fopenmp -w /tmp/pip-install-z3t4vdud/mujoco-py/mujoco_py/cymj.c:53:10: fatal error: Python.h: No such file or directory #include "Python.h" ^~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-z3t4vdud/mujoco-py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-t_1q5w6p/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-z3t4vdud/mujoco-py/ 循环的每次迭代中重新定义结果。我相信您想要的是附加结果:

for y in pool