[Torch]的安装

1 安装Torch

本文介绍Torch7的安装方法,因为本人安装Torch前安装了caffe,所以可能CUDA、cudnn、Blas等Torch可能需要用来的库的安装就不再重复介绍了,相关依赖出现问题的的猿友可以参考史上最全的caffe安装过程

1.1 安装luarock

lua是通过luarock来进行软件包管理的,Torch7的接口是lua,因此需要先安装Lua,本人安装的是lua52,安装过程主要参考Torch官方文档

1.2 参考官方文档遇到的问题

记录参考Torch官方文档安装Torch7出现一些问题。
qlua installation

luarocks install qtlua         //not qlua

(1) error: found unsuitable Qt version from NOTFOUND, this code requires Qt4.x
solution:
1.exclude anaconda env from your path.
Referrence
2.第二步:

sudo apt-get install qt-sdk

(2) error: module ‘qttorch’ not found: no field package.preload[‘qttorch’] it occur when I use qlua to run some sh
solutions:

luarocks install qttorch

(3) error: readline.h not found
after type ./install.sh , error readline.c:7:31: fatal error: readline/readline.h: No such file or directory #include <readline/readline.h>
solution:

sudo apt-get install libreadline-dev

reference

(4) error: luarocks install image , and occur getting connection timed out for couple of hours
solution:

git clone https://github.com/torch/image.git
cd image
luarocks make image-1.1.alpha-0.rockspec

reference

(5) error: module 'hdf5' not found:No LuaRocks module found for hdf5,
while run the generate heatmap model by type “ th run-hg.lua ../data/tennis jpg”
problem:
luarocks download package through git protocol, which will use ssh protocol. So we have to convert git download protocol to https protocol.
Solotion:

git config –global url.https://.insteadOf ssh://git
vim ~/.gitconfig

To certain .gitconfig like:

[url “https://”]
    insteadOf = git://

(最好不要再添加别替换,否则会产生多重替换而我们看不出来。有时候我们在output_log里面看到依然git://github.com,但是这并不一定真实,git://被替换为https://有时候不会显式出来)
then type:

luarocks install hdf5      
#it will print nothing, but running in background.
luarocks intsll hdf5 --verbose     
#It will print all the imformation when downloading and compiling.

Reference

(6) warning: Failed loading manifest while type ”luarocks list”
Failed loading manifest for /home/werner/.luarocks/lib/luarocks/rocks: ~/.luarocks/lib/luarocks/rocks/manifest: No such file or directory
Solution:

mkdir -p ~/.luarocks/lib/luarocks/rocks
luarocks-admin make-manifest --local-tree --tree=$HOME/.luarocks

referrene

(7) error: getrf : Lapack library not found in compile time
solution:

git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS
make NO_AFFINITY=1 USE_OPENMP=1
sudo make install

then:

CMAKE_LIBRARY_PATH=/opt/OpenBLAS/include:/opt/OpenBLAS/lib:$CMAKE_LIBRARY_PATH 
luarocks install torch

按照以上步骤就能解决问题,网上大多数人都能解决问题。但我们的机器依然报错。
Reference
后来我查看luarocks install torch输出发现:
OpenBlas detected
It seems OpenBlas has not been compiled with Lapack support
Then I try:

sudo apt-get install liblapack-dev

reinstall OpenBlas, then I found following information in top output:
OpenBLAS: Detecting fortran compiler failed. Cannot compile LAPACK. Only compile BLAS.
Google it found:
Reference
error OpenBLAS: Detecting fortran compiler failed. Please install fortran compiler, e.g. gfortran, ifort.
So,

sudo apt-get install gfortran

Then reinstall OpenBlas , it resolved.

转载于:https://www.cnblogs.com/fariver/p/7460320.html

### torch 安装错误解决方案 在 Windows 10 下安装 PyTorch 及其扩展包(如 `torch_scatter` 和 `torch_sparse`)时可能会遇到各种问题,以下是针对常见错误的综合解决方案。 #### 1. 环境配置 确保 Python 版本与 PyTorch 的兼容性。PyTorch 支持的最低版本通常为 Python 3.7 或更高版本[^1]。建议使用 Anaconda 创建虚拟环境来管理依赖项: ```bash conda create -n pytorch_env python=3.9 conda activate pytorch_env ``` 如果未安装 CUDA,则需选择 CPU-only 版本;否则应根据显卡驱动程序支持的 CUDA 版本来匹配合适的 PyTorch 轮子文件。 #### 2. 使用官方推荐的方式安装 PyTorch 访问 [PyTorch官网](https://pytorch.org/get-started/locally/) 并根据操作系统、CUDA 配置自动生成适合的安装命令。例如,在不启用 GPU 加速的情况下可以运行如下指令完成基础框架部署: ```bash pip install torch torchvision torchaudio cpuonly ``` 对于需要 GPU 支持的情况,请替换相应参数以加载对应于本地硬件条件下的预编译二进制文件。 #### 3. 处理特定组件安装失败情况 当尝试通过 pip 单独获取某些附加模块像 `torch_scatter`, 如果直接调用标准方法报错提示无法构建 whl 文件时, 推荐采用 conda 渠道或者手动指定源地址来进行操作: - **Conda 方式**: ```bash conda install -c pyg torch-scatter ``` - **Pre-built Wheels 方法**: 访问 https://pytorch-geometric.com/whl/, 找到适合自己计算平台(CPU/CUDA X.X)以及当前已安裝之 PyTorch 版本相吻合的链接後执行下载并安装动作. #### 4. 自定义目标目录安装(备用选项) 若常规途径依旧碰壁可考虑更改默认存储位置规避权限冲突等问题发生 : ```bash pip install --upgrade pip setuptools wheel pip install --target=D:\custom_path\lib\site-packages torch-scatter ``` 注意调整实际路径至个人需求处[^3]. --- ### 示例代码片段展示如何验证安装成功与否 下面提供了一段简单的测试脚本用于确认所装设库能否正常运作无误. ```python import torch from torch_geometric.data import Data edge_index = torch.tensor([[0, 1], [1, 0]], dtype=torch.long) data = Data(edge_index=edge_index, num_nodes=2) print(data) ``` 如果一切顺利的话应该能够看到类似于这样的输出结果而不抛异常 : ``` Data(edge_index=[2, 2], num_nodes=2) ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值