ubuntu-server20.04 静态ip cuda11.2 cudnn conda虚拟环境 opencv h264

修改静态ip

ifconfig可以查看,所有网络属性
转到网络配置目录cd /etc/netplan     查看文件ls    修改文件sudo vim 文件名.yaml
例:sudo vim 00-installer-config.yaml   
(我这个是双网口的,eno1、eno2,如果单网口,只用配置一个eno1就可以了)

注意缩进! ! ! ! ! ! !

# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      dhcp4: no      
      addresses: [192.168.1.7/24]
      optional: true
      gateway4: 192.168.1.1
      nameservers:
        addresses: [255.255.255.0]
    eno2:
      dhcp4: no      
      addresses: [192.168.100.198/24]
      optional: true
      gateway4: 192.168.1.1
      nameservers:
        addresses: [255.255.255.0]
  version: 2

配置完成后,运行sudo netplan apply , 重启网卡驱动,配置完成!!

更换阿里镜像,apt-get下载变快

打开/etc/apt/sources.list ,输入一下内容

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
 
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

完成后,sudo apt-get update 再 sudo apt-get upgrade

安装显卡驱动,去官网查看最新驱动版本

sudo apt-get install gcc
sudo apt-get install make
sudo apt install nvidia-cuda-toolkit
sudo apt install dkms build-essential linux-headers-generic

禁用 nouveau 驱动
sudo vim /etc/modprobe.d/blacklist.conf
在文件末尾加入:
blacklist rivafb
blacklist vga16fb
blacklist nouveau
blacklist nvidiafb
blacklist rivatv
options nouveau modeset=0
blacklist lbm-nouveau
alias nouveau off
alias lbm-nouveau off

禁用 nouveau 内核模块
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
sudo update-initramfs -u

卸载旧版本的nvidia驱动:sudo apt-get --purge remove nvidia-*
重启: sudo reboot

sudo chmod a+x NVIDIA-Linux-x86_64-450.66.run
sudo ./你的显卡驱动.run -no-x-check -no-nouveau-check -no-opengl-files

Would you like to register the kernel module sources with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later. ——NO
Install NVIDIA’s 32-bit compatibility libraries?——NO
Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up. ——YES

安装完毕,重启: sudo reboot
挂载驱动: modprobe nvidia
检查是否安装成功:nvidia-smi

安装cuda11.2 cudnn

wget 下载链接
sudo sh cuda_11.1.1_455.32.00_linux.run

配置cuda环境变量

~/.bashrc文件中添加:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda

更新变量:source ~/.bashrc
测试:nvcc -V

下载cudnn,linux(x64) 解压后

sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
配置完成

Anconda安装 + opencv h264 依赖:

安装包链接:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

安装命令 bash Anaconda3-5.3.0-Linux-x86_64.sh
回车按住略过许可证,
Do you approve the license terms? [yes|no] 输入yes,
直接安装默认路径,
by running conda init? [yes|no] 再no,
在.bashrc中添加  export PATH="/root/anaconda3/bin:$PATH"
完成后source ~/.bashrc

创建虚拟环境:conda create -n ceak python=3.7
修改pip镜像源:
1.在“主目录”下创建.pip文件夹,进入文件夹使用命令touch pip.conf创建pip.conf文件
2.输入以下内容然后保存即可
[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com

安装一个opencv 依赖的python包:pip install numpy

安装openh264:conda install -c conda-forge openh264
安装opencv依赖:
sudo apt install ubuntu-restricted-extras
sudo apt install build-essential cmake git python3-dev python3-numpy libavcodec-dev libavformat-dev libswscale-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libgtk-3-dev libpng-dev libjpeg-dev libopenexr-dev libtiff-dev libwebp-dev libopencv-dev

sudo apt remove -y x264 ffmpeg libx264-dev
sudo apt install x264 libx264-dev ffmpeg pkg-config 
依赖安装完成

下载源码,并进行编译opencv

下载opencv源码(我是4.5.3):
https://github.com/opencv/opencv.git
当然你也可以走捷径:https://pan.baidu.com/s/1Z3KbRWyW_wYMYuUK6_SHjw 
提取码:lyb8
解压后,opencv目录下新建build文件夹,再执行下边命令
cmake -D OPENCV_ENABLE_NONFREE=ON -D BUILD_opencv_python2=OFF -D WITH_GDAL=ON -D OPENCV_PYTHON3_VERSION=3.7 -D PYTHON_DEFAULT_EXECUTABLE=/home/roo/anaconda3/envs/ceak/bin/python -D PYTHON3_LIBRARY=/home/roo/anaconda3/envs/ceak/lib/python3.7 -D PYTHON3_EXECUTABLE=/home/roo/anaconda3/envs/ceak/bin/python -D PYTHON3_INCLUDE_DIR=/home/roo/anaconda3/envs/ceak/include/python3.7m -D PYTHON3_PACKAGES_PATH=/home/roo/anaconda3/envs/ceak/lib/python3.7/site-packages ..
(这里要注意,conda虚拟环境路径、python版本)
make -j$[$(nproc)-1] 
sudo make install
opencv编译完成

安装Moviepy ImageMagick

安装:sudo apt install imagemagick

使用convert报错: ImageMagick is not installed
解决方法:\Lib\site-packages\moviepy\config_defaults.py中的 IMAGEMAGICK_BINARY
改为自己路径 magick.exe or /usr/bin/convert

报错:@/tmp/tmp5rk19_ox.txt
解决方法:   修改文件 /etc/ImageMagick-6/policy.xml
<policy domain="path" rights="none" pattern="@*" /> 
改成
<!-- <policy domain="path" rights="none" pattern="@*" /> -->
Moviepy 重点要记:处理视频一定要最后再进行叠加或合并处理,可以提高速度,至于GPU加速解码,弄完之后速度并没有什么变化,2.0版本的尝试后太多问题。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2022年3月15日 下午10:17
下一篇 2022年3月16日 下午7:02

相关推荐

此站出售,如需请站内私信或者邮箱!