最细致的3DGS配置代码!(配置WSL2-colmap-gsplat)

2026/01/10

1. 安装 Cuda 11.8

sudo apt update 
sudo apt install build-essential

安装cuda,这里的wget也可以在简介中的网盘下载

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

安装完成后,通过下面指令打开vscode:

code .

然后再文件最后加入:

export PATH=/usr/local/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH

2. 安装colmap

为了支持调用CUDA的colmap,我们需要自己进行编译,首先安装各种依赖

sudo apt-get update && sudo apt-get install -y git cmake build-essential ninja-build libboost-program-options-dev libboost-filesystem-dev libboost-graph-dev libboost-system-dev libboost-test-dev libeigen3-dev libfreeimage-dev libgoogle-glog-dev libgflags-dev libglew-dev libqt5opengl5-dev qt5-default libatlas-base-dev libsuitesparse-dev libcgal-dev libcgal-qt5-dev libceres-dev libflann-dev liblz4-dev libsqlite3-dev libmetis-dev

然后用gitclone拉取代码,并切换分支:(也可以从百度云下载)

git clone https://github.com/colmap/colmap.git 
cd colmap # 强烈建议切换到 3.9.1 分支,比 dev 分支更稳定,不容易报错 
git checkout 3.9.1

编译:

mkdir build
cd build
cmake .. -GNinja -DCMAKE_CUDA_ARCHITECTURES=native
ninja  # 这里会跑很久,但是有一个进度条,等待进度条走完就行了
sudo ninja install

3. 测试colmap(可选)

使用我提供的数据进行测试,也可以自己拍

cd ~/code/script
sudo chmod +x mapping.sh
./mapping.sh ~/code/data/

4. Miniconda

下载 Miniconda 安装脚本,或者直接从百度云下载

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc

4. 安装pytorch

查看当前conda的源

conda config --show-sources

删除掉系统的配置文件:

rm /home/mz/miniconda3/.condarc

输入:

code ~/.condarc

编辑为:

channels:
    - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
    - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    - nodefaults
show_channel_urls: true

创建一个虚拟环境

conda create -n gsplat python=3.10
conda activate gsplat

将 pip 源永久设置为清华源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
安装pytorch
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

验证是否成功:

python
> import torch 
> torch.cuda.is_available()

5. 安装gsplat

pip install gsplat

为了训练,我还需要将gsplat的源码下载下来:

git clone https://github.com/nerfstudio-project/gsplat.git
cd gsplat/examples

安装其他训练所需要的库:

pip install -r requirements.txt --no-build-isolation

开始训练:

python simple_trainer.py default --data_dir ~/code/script/3dgs_project/output/ --data_factor 1 --save_ply

重建世界LAB

最细致的3DGS配置代码!(配置WSL2-colmap-gsplat) | 博客