備忘隨筆——安裝centos7之後,裝smlayer,帶ffmpeg的opencv,anaconda,tensorflow, 配置虛擬環境中的python,opencv

由於tensorflow只能運行在64位機,我還是下決心把我4g內存的老筆記本從centos6換裝成了centos7.

下面是安裝過程中的note筆記,未經整理,僅作備忘。

2019-9-27

配置epel源
https://www.cnblogs.com/lyz108/p/10293430.html
缺省yum源的服務器通常在國外,安裝時速度比較慢。爲了提高安裝rpm包的速度,可以將yum源配置爲國內的阿里repo。2

1、先備份系統原有的repo
[root@192 jello]# cd /etc/yum.repos.d/
[root@192 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@192 yum.repos.d]# mkdir backup
[root@192 yum.repos.d]# mv *.repo ./backup/
2、獲取阿里centos7的base-repo
[root@192 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@192 yum.repos.d]# ls
backup  CentOS-Base.repo
3、清除並重新生成yum cache
[root@192 yum.repos.d]# yum clean all
[root@192 yum.repos.d]# yum makecache
4、測試一下新的yum源是否可用
[root@localhost yum.repos.d]# yum install -y screen
5、獲取阿里centos7的epel-repo
[root@localhost yum.repos.d]# wget https://mirrors.aliyun.com/repo/epel-7.repo
6、清除並創建cache
[root@localhost yum.repos.d]# ls
backup  CentOS-Base.repo  epel-7.repo
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache

配置rpmforge源
http://rpmfind.net/linux/rpm2html/search.php?query=rpmforge-release
[root@192 Downloads]# rpm -ivh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
配置rpmfusion源
http://rpmfusion.org/Configuration
yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm

安裝smplayer
yum install smplayer*
---------------------------------------------------------------------------------------------------
安裝opencv3.4.6
安裝ffmpeg
yum install ffmpeg ffmpeg-devel
安裝依賴項
yum install cmake gcc gcc-c++ gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libjpeg-devel libpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm

yum install python-devel numpy
yum install libdc1394-devel
yum install libv4l-devel
yum install gstreamer-plugins-base-devel

cd /home/jello/Download/opencv-3.4.6
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_FFMPEG=ON -D OPENCV_EXTRA_MODULES_PATH=/home/jello/Download/opencv_contrib-3.4.6/modules ..

make
su
make install

[root@192 ld.so.conf.d]# vi opencv-3.4.6.conf

/usr/local/lib64
[root@192 ld.so.conf.d]# ldconfig

安裝qt-opensource-linux-x64-5.9.8.run  (補記於2020/4/19,新臺式機上裝雙系統)

http://download.qt.io/official_releases/qt/5.9/5.9.8/

yum -y install mesa-libGL-devel mesa-libGLU-devel freeglut-devel
chmod +x qt-opensource-linux-x64-5.9.5.run
./qt-opensource-linux-x64-5.9.5.run
斷網能跳過登錄賬戶頁面
安裝組件選擇,不勾選andriod和最後一個script(已過時),其他的全選
添加動態鏈接庫
cd /etc/ld.so.conf.d/
vi qt5.9.8.conf
/opt/Qt5.9.8/5.9.8/gcc_64/lib
/opt/Qt5.9.8/Tools/QtCreator/lib
ldconfig
添加環境變量
vi ~/.bashrc
export PATH=$PATH:/opt/Qt5.9.8/5.9.8/gcc_64/bin/:/opt/Qt5.9.8/Tools/QtCreator/bin

這樣只能在root環境下使用,普通用戶jello居然無法使用,而且居然沒有桌面快捷方式!

vi /etc/profile

export PATH=$PATH:/opt/Qt5.9.8/5.9.8/gcc_64/bin/:/opt/Qt5.9.8/Tools/QtCreator/bin 後jello下命令行輸入qtcreator可用

添加桌面快捷方式

CentOS 7 創建qtcreator快捷方式
在/usr/share/applications/文件夾下,用vim新建一個qtcreator.desktop的文件

[Desktop Entry]
Type=Application
Name=qtcreator
Exec=/opt/Qt5.9.8/Tools/QtCreator/bin/qtcreator
GenericName=qtcreator
Comment=Qt development tools
Icon=/opt/Qt5.9.8/5.9.8/gcc_64/doc/global/template/images/Qt-logo.png
Categories=Application;Development;
Terminal=false

這樣菜單中Applications下面纔有了Programing->QtCreator !

QT中opencv項目pro文件中添加

INCLUDEPATH += /usr/local/include \
               /usr/local/include/opencv \
               /usr/local/include/opencv2
 
LIBS += /usr/local/lib64/libopencv*
-------------------------------------------------------------------------------------------------

anaconda清華鏡像
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

Anaconda介紹、安裝及使用教程
https://www.jianshu.com/p/62f155eb6ac5

[jello@192 Downloads]$ bash ./Anaconda3-4.1.1-Linux-x86_64.sh
Anaconda3 will now be installed into this location:
/home/jello/anaconda3
安裝tensorflow
https://blog.csdn.net/zhaoliang027/article/details/80002647
下載網址爲https://pypi.org/project/tensorflow/1.4.0/#files


conda create -n tensorflow python=3.5
The following NEW packages will be INSTALLED:

    certifi:    2016.2.28-py35_0
    openssl:    1.0.2l-0        
    pip:        9.0.1-py35_1    
    python:     3.5.4-0         
    readline:   6.2-2           
    setuptools: 36.4.0-py35_1   
    sqlite:     3.13.0-0        
    tk:         8.5.18-0        
    wheel:      0.29.0-py35_0   
    xz:         5.2.3-0         
    zlib:       1.2.11-0

然後進入conda環境並安裝tensorflow

source activate tensorflow若不能激活,則可能是沒有載入anaconda3的安裝路徑,需要執行$ export PATH=/home/zhaoliang/software/anaconda3/bin:$PATH

cd ~/download #我是將下載好的東西放在了download文件夾裏

pip install --ignore-installed --upgradetensorflow-1.4.0-cp35-cp35m-manylinux1_x86_64.whl

3.測試是否安裝成功

import tensorflow as tf
————————————————
版權聲明:本文爲CSDN博主「zhaoliang027」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/zhaoliang027/article/details/80002647


>>> hello=tf.constant('hello')
>>> sess=tf.Session()
2019-09-25 18:29:49.498754: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
>>> a=tf.constant(111)
>>> b=tf.constant(222)
>>> print(sess.run(a+b))
333

import os  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 這是默認的顯示等級,顯示所有信息  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只顯示 warning 和 Error   
os.environ["TF_CPP_MIN_LOG_LEVEL"]='3' # 只顯示 Error  
————————————————
版權聲明:本文爲CSDN博主「一個處女座的程序猿」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_41185868/article/details/79127838

>>> import os
>>> os.environ["TF_CPP_MIN_LOG_LEVEL"]='2'
>>> hello=tf.constant('hello')
>>> sess=tf.Session()
>>> a=tf.constant(111)
>>> b=tf.constant(222)
>>> print(sess.run(a+b))
>>> quit()
(tensorflow) [jello@192 Downloads]$ source deactivate
[jello@192 Downloads]$ conda info --envs
# conda environments:
#
tensorflow               /home/jello/anaconda3/envs/tensorflow
root                  *  /home/jello/anaconda3

第一次導入時報錯:
>>> import tensorflow as tf
/home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:469: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:470: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:471: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:472: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:473: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:476: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

cp /home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py /home/jello/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py.bak

將上面文件中警告的469等6行的np.dtype([("resource", np.ubyte, 1)])改爲提示的np.dtype([("resource", np.ubyte, (1,))])

============================================================================================
[jello@192 ~]$ source activate tensorflow
(tensorflow) [jello@192 ~]$ conda install matplotlib

補記於2019.11.27

前面用anaconda創建了虛擬環境tensorflow如下:

conda create -n tensorflow python=3.5

之後在該環境下安裝了tensorflow1.4

今天在該環境安裝opencv3.4如下:

conda env list

source activate tensorflow

(tensorflow) [jello@192 tensorflow]$ pip install opencv-python==3.4.6.27
(tensorflow) [jello@192 tensorflow]$ pip install opencv-contrib-python==3.4.27

(tensorflow) [jello@192 tensorflow]$ python

>>> import cv2
>>> cv2.__version__
'3.4.6'

再補記於2020.4.19(新臺式機裝雙系統後配置opencv失敗,按如上操作網速太慢安裝不了)

照該文章介紹的從清華鏡像源安裝,沒有指定具體版本,pip默認給我安裝了最新4.2版本的opencv與opencv contrib.待使用

https://www.cnblogs.com/ws17345067708/p/11043603.html

(tensorflow) [jello@192 ~]$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-python
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/00/aa/5880b514dff3642161bda4af39aa2a544cb5949d9e194d1ef81e06fcc2f2/opencv_python-4.2.0.34-cp35-cp35m-manylinux1_x86_64.whl (28.2 MB)
     |████████████████████████████████| 28.2 MB 219 kB/s
Requirement already satisfied: numpy>=1.11.1 in ./anaconda3/envs/tensorflow/lib/python3.5/site-packages (from opencv-python) (1.18.2)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.2.0.34
(tensorflow) [jello@192 ~]$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-contrib-python
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/17/e4/aac4454c7df99b264fc53a12c25a40c76dc5b417f9866f6d6d1554aac80e/opencv_contrib_python-4.2.0.34-cp35-cp35m-manylinux1_x86_64.whl (34.2 MB)
     |████████████████████████████████| 34.2 MB 113 kB/s
Requirement already satisfied: numpy>=1.11.1 in ./anaconda3/envs/tensorflow/lib/python3.5/site-packages (from opencv-contrib-python) (1.18.2)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.2.0.34

補記於2019.11.29凌晨00:15

anaconda中tensorflow環境中安裝scikit-learn 0.18.1

首先輸入命令

conda install scikit-learn==0.18.1 網絡太慢失敗

CondaError: CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.continuum.io/pkgs/free/linux-64/scikit-learn-0.18.1-np113py35_1.tar.bz2>
Elapsed: -

按上面<>中的地址在瀏覽器中下載文件mv到anaconda的pkgs中

(之前(tensorflow) [jello@192 ~]$ conda install scikit-learn==0.18.1 --offline以及路徑在Download下安裝都莫名失敗)

(tensorflow) [jello@192 ~]$ conda install /home/jello/anaconda3/pkgs/scikit-learn-0.18.1-np113py35_1.tar.bz2安裝成功了

In [2]: import numpy as np

In [3]: from sklearn import datasets

In [4]: import matplotlib.pyplot as plt

In [5]: %matplotlib

運行成功

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章