1. 程式人生 > 其它 >完美配置Linux軟體開發環境(c++:VScode+opencv+QT,python:Pycharm+opencv+QT+tensorflow)

完美配置Linux軟體開發環境(c++:VScode+opencv+QT,python:Pycharm+opencv+QT+tensorflow)

技術標籤:linux

一、 工具準備篇

1. .deb安裝,eg: chrome、搜狗輸入法for Linux、堅果雲

sudo dpkg -i ***.deb

2. install vim/gedit 文字編輯器

sudo apt-get install vim

sudo apt-get installgedit

3. 更換apt國內源

# 備份原來的源

sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

# 更換源 也可使用圖形介面配置:系統設定 -> 軟體和更新 選擇下載伺服器 -> "mirrors.aliyun.com"

sudo vi /etc/apt/sources.list

將以下國內源複製進文件:

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

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

# 更新源

sudo apt-get update

#更新軟體

sudo apt-get upgrade

4. 將系統自帶python3連結到python

# 將系統自帶的python3連結到python

sudo ln -s /usr/bin/python3.8 /usr/bin/python

5. 安裝pip3

# 安裝pip

sudo apt-get install python3-pip # 輸入pip3 -V檢視pip3的版本

# 更新pip3

sudo pip3 install --upgrade pip

# 將pip3連結到pip,可直接用pip命令

sudo ln -s /usr/bin/pip3 /usr/bin/pip

解決pip下載慢的問題

方法1:可以在使用pip的時候在後面加上-i引數,指定pip源

pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

方法2:更換pip國內源

#建立pip資料夾

cd .config

sudo mkdir pip

cd pip

#建立pip.cong檔案

sudo touch pip.conf

#編輯pip.conf檔案

sudo vim pip.conf

在pip.conf檔案中新增清華大學的pypi映象,要是想用其他的映象,替換成相應的地址即可。

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

進入boot模式(sudo su),直接複製到終端執行

apt-get install python3-pip
ln -s /usr/bin/pip3 /usr/bin/pip
mkdir ~/.config/pip
(
echo "[global]
timeout=6
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url=
    https://mirrors.aliyun.com/pypi/simple"
echo "[install]
trusted-host=
    pypi.tuna.tsinghua.edu.cn
    mirrors.aliyun.com"
) >> ~/.config/pip/pip.conf
pip3 install --upgrade pip

6.安裝顯示卡驅動

https://blog.csdn.net/qq_42699580/article/details/104429749

二、 VScode開發環境

1. 急速下載VScode

參考:https://zhuanlan.zhihu.com/p/112215618

首先在官網找到需要下載的檔案,點選下載。

在瀏覽器或者下載軟體中就可以看到這麼一個下載地址了,將其複製下來(如下圖箭頭所指)。

然後將紅框內的部分更換為如下內容:vscode.cdn.azure.cn<--------就是左邊這個

更新後的地址為:https://vscode.cdn.azure.cn/stable/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/code_1.52.1-1608136922_amd64.deb

安裝.deb

sudo dpkg -i code_1.52.1-1608136922_amd64.deb

2. 安裝依賴、外掛

安裝依賴包:

sudo apt-get install gcc g++ gdb

安裝VScode外掛:

1.C/C++
2.Code Runner
3.Run in Terminal

三、安裝OpenCV

參考:https://blog.csdn.net/WJ_SHI/article/details/107605439

1. 下載opencv原始碼https://opencv.org/ eg: opencv-4.5.1.zip

2.安裝依賴

#libjasper-dev包無法定位,增加庫並更新atp

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"

sudo apt-get update

# 安裝opencv依賴

sudo apt-get install build-essentiallibgtk2.0-devlibavcodec-devlibavformat-devlibjpeg-devlibtiff-devlibswscale-devlibpng-devlibjasper-dev

3. 安裝opencv

# install cmake 工具

sudo apt-get install cmake

# 解壓.zip,將解壓後文件移動到/opt目錄下

cd /*** # 下載的opencv-4.5.1.zip檔案所在目錄

unzip opencv-4.5.1.zip

sudo mvopencv-4.5.1 /opt

cd /opt/opencv-4.5.1

sudo mkdir build

cd build

sudo cmake ..

sudo make

sudo make install

注意:最後所有檔案將被安裝到目錄“/usr/local/”下面。

4. 修改環境變數配置

安裝完成後,手動建立opencv.pc:

cd /usr/local/lib

sudo mkdir pkgconfig && cd pkgconfig

sudo gedit opencv.pc

然後新增:

prefix=/usr/local
exec_prefix=${prefix}
includedir=/usr/local/include
libdir=/usr/local/lib

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.4.0
Libs: -L${exec_prefix}/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir}

更改環境變數,輸入命令:

sudo gedit /etc/bash.bashrc

開啟之後,在檔案最後面新增以下內容:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

儲存退出,opencv基本上就安裝完成了。通過 pkg-config 檢視 opencv 版本:

pkg-config --modversion opencv

在bash.bashrc檔案末尾加上

PKG_CONFIG=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

儲存後退出,執行以下指令測試opencv配置成功:

ldconfig -p | grep opencv

5. python 連結opencv

pip install opencv-python

進行python測試,如下:

$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
4.5.1