【mega-nerf】调包失败&pip install失败解决方案

文章讨论了在Python中调用模块时遇到的问题,包括sys.path.append()无法添加模块路径的解决方案,以及使用os库来正确添加父目录。另外,提到了pip安装时的ConnectTimeoutError错误,建议使用阿里云、清华或中科大的镜像源。最后,文章指出了torch.jit.save()在保存模型时可能出现的问题,并提供了两种存储模型的方法。
摘要由CSDN通过智能技术生成

Problem 1. 调包失败

在这样的层级架构里调包,输出无法找到 mega_nerf

在这里插入图片描述

直接用 sys.path.append() 没有作用

# import sys
# print(sys.path)
# sys.path.append("/home/paper/Desktop/meganerf/mega_nerf/") # 对3.6.7以上python版本不适用

解决方案

在开头添加:

import sys
import os
dir_path=os.path.dirname(os.path.realpath(__file__))
parent_dir_path=os.path.abspath(os.path.join(dir_path, os.pardir))
sys.path.insert(0,parent_dir_path)

Problem 2. pip install失败

pip install ConnectTimeoutError,添加对应镜像网站。

# 阿里云镜像 http://mirrors.aliyun.com/pypi/simple/
# 清华镜像 https://pypi.tuna.tsinghua.edu.cn/simple/
# 中科大镜像
pip install XX --index-url https://pypi.douban.com/simple

Problem 3. torch.jit.save()保存模型以 .pth 作为路径结尾

# 两种存储方式
torch.jit.save(m, 'non/existent/path/model.pth')
torch.save(m, 'non/existent/path/model.pth')

torch.jit.save() produces complex c++ error when path does not exist

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值