import tensorflow时报错File "stdin", line 1 IndentationError: unexpected indent

本文详细介绍了在使用Python导入TensorFlow时遇到的常见缩进错误:'IndentationError: unexpected indent'。错误通常由代码中多余的空格引起,Python对代码缩进非常敏感。文章提供了具体的错误示例,并给出了简单的解决方案:删除import语句前的多余空格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.问题描述

在装好tensorflow时出现了报错
具体错误为:File " stdin ", line 1 IndentationError: unexpected indent

>>>  import tensorflow as tf
  File "<stdin>", line 1
    import tensorflow as tf
    ^
IndentationError: unexpected indent

2.解决

这个错误是缩进不对,检查一下是不是多打了空格,python对缩进是比较敏感的。

把import前空格删除就好了。如图,再测试就没有问题了。

在这里插入图片描述

End。

(pytorch) C:\Users\pc>python Python 3.9.21 (main, Dec 11 2024, 16:35:24) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> from torch.utils.data import Dataset >>> >>> class Voxelization: ... def __init__(self, voxel_size=(0.16, 0.16, 4), max_points=32): ... self.voxel_size = voxel_size # 体素尺寸 (x, y, z) ... self.max_points = max_points # 每个体素最大点数 ... >>> def __call__(self, points): File "<stdin>", line 1 def __call__(self, points): IndentationError: unexpected indent >>> # 将点云划分为体素 >>> coords = (points[:, :3] / torch.tensor(self.voxel_size)).int() File "<stdin>", line 1 coords = (points[:, :3] / torch.tensor(self.voxel_size)).int() IndentationError: unexpected indent >>> unique_voxels, inverse_indices = torch.unique(coords, dim=0, return_inverse=True) File "<stdin>", line 1 unique_voxels, inverse_indices = torch.unique(coords, dim=0, return_inverse=True) IndentationError: unexpected indent >>> voxel_features = [] File "<stdin>", line 1 voxel_features = [] IndentationError: unexpected indent >>> for idx in range(len(unique_voxels)): File "<stdin>", line 1 for idx in range(len(unique_voxels)): IndentationError: unexpected indent >>> mask = (inverse_indices == idx) File "<stdin>", line 1 mask = (inverse_indices == idx) IndentationError: unexpected indent >>> voxel_points = points[mask][:self.max_points] # 截断超量点 File "<stdin>", line 1 voxel_points = points[mask][:self.max_points] # 截断超量点 IndentationError: unexpected indent >>> # 特征编码:取点坐标均值+反射强度 >>> features = torch.cat([voxel_points.mean(dim=0), voxel_points[:, 3].mean().unsqueeze(0)]) File "<stdin>", line 1 features = torch.cat([voxel_points.mean(dim=0), voxel_points[:, 3].mean().unsqueeze(0)]) IndentationError: unexpected indent >>> voxel_features.append(features) File "<stdin>", line 1 voxel_features.append(features) IndentationError: unexpected indent >>> return torch.stack(voxel_features) # (N_voxels, 特征维度) File "<stdin>", line 1 return torch.stack(voxel_features) # (N_voxels, 特征维度) IndentationError: unexpected indent
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值