Install OpenCV _ x86 _ Ubuntu

Ubuntu 21 apt update failed

# https://serverfault.com/questions/1108176/ubuntu-server-21-04-update-error-on-apt-update
# https://serverfault.com/questions/1106694/unable-to-run-apt-update-on-ubuntu-21-10
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo sed -i -r 's/([a-z]{2}.)?archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list 
sudo sed -i -r 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo apt update

# Manually check that every "deb" in /etc/apt/sources.list" begins with 
http://old-releases.ubuntu.com/

# Then apt update should be okay wihout errors
sudo apt update

By Conda

Conda helps you to build an isolated environment to prevent from package version conflict with pre-installed packages by OS.


### Prepare Conda
sudo apt install -y curl git wget

# Download Conda from Webiste https://www.anaconda.com/products/distribution
# Ref: https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
bash Anaconda3-2022.10-Linux-x86_64.sh
# ENTER
# yes
# ENTER
# yes # to run conda init

sudo reboot

### Use Conda to Install OpenCV 4.6
conda create -n d457 python=3.8
# y

conda activate d457
conda install opencv=4.6
# y

#####
# Change library path whenever we activate "d457" environment
echo $CONDA_PREFIX
cd $CONDA_PREFIX
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/env_vars.sh
touch ./etc/conda/deactivate.d/env_vars.sh

#####
# edit ./etc/conda/activate.d/env_vars.sh
vim ./etc/conda/activate.d/env_vars.sh
# add the following lines into ./etc/conda/activate.d/env_vars.sh

#!/bin/sh
export OLD_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH=/home/n9420/anaconda3/envs/d457/lib/

#####
# edit ./etc/conda/deactivate.d/env_vars.sh
vim ./etc/conda/deactivate.d/env_vars.sh
# add the following lines into ./etc/conda/deactivate.d/env_vars.sh
#!/bin/sh
export LD_LIBRARY_PATH=${OLD_LD_LIBRARY_PATH}
unset OLD_LD_LIBRARY_PATH

### 
conda deactivate

conda activate d457

echo $LD_LIBRARY_PATH
ll $LD_LIBRARY_PATH/libopencv*


###

# For future use of openCV, please rememebr to use 
conda activate d457

Last updated