CentOS OpenCV-python
yum -y install epel-releaseyum -y install python36 python36-devel python36-pip python36-numpypip3 install bpython
·
文章目录
- 安装 Python3.6 及 opencv-python
- 测试 OpenCV
- 安装 Django 并测试
- 安装 Apache 和 mod_wsgi
安装 Python3.6 及 opencv-python
yum -y install epel-release
yum -y install python36 python36-devel python36-pip python36-numpy
reboot(可选)
pip3 install --upgrade pip
pip install bpython
pip install opencv-python
# 如果安装中间提示低版本的numpy无法卸载,则强行安装新版本的numpy。
pip install numpy --ignore-installed numpy
测试 OpenCV
在 import cv2的时候报错,如下:
>>> import cv2 as cv
Traceback (most recent call last):
File "<input>", line 1, in <module>
import cv2 as cv
File "/usr/local/lib64/python3.6/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: libSM.so.6: 无法打开共享对象文件: 没有那个文件或目录
检查libSM.so.6
在哪个包里,并安装它。
[root@localhost ~]# yum whatprovides libSM.so.6
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
libSM-1.2.2-2.el7.i686 : X.Org X11 SM runtime library
源 :base
匹配来源:
提供 :libSM.so.6
yum -y install libSM
yum -y install libXrender
yum -y install libXext
#================================测试 OpenCV================================
[root@localhost ~]# bpython
bpython version 0.18 on top of Python 3.6.8 /usr/bin/python3.6
>>> import cv2 as cv
>>> print(cv.__version__)
4.1.0
安装 Django 并测试
pip install django==2.1.8 # django 版本太高要求相应的库也高 2.X就可以了
#================================测试 Django================================
[root@localhost ~]# bpython
bpython version 0.18 on top of Python 3.6.8 /usr/bin/python3.6
>>> import django
>>> django.VERSION
(2, 1, 8, 'final', 0)
测试建立网站
django-admin startproject wwwsite # 建立项目
cd wwwsite
python3 manage.py startapp webtt # 在项目下建立 app
#=== vi wwwsite/settings.py ===
ALLOWED_HOSTS = ["*",] # 允许所有访问
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'webtt', #加入刚建的 app
]
#=== vi webtt/views.py ===
# coding:utf-8
from django.http import HttpResponse
def index(request):
return HttpResponse(u"欢迎光临 whudee!")
#=== vi wwwsite/urls.py ===
from django.contrib import admin
from django.urls import path
from webtt import views as webtt_views # new
urlpatterns = [
path('', webtt_views.index), # new
path('admin/', admin.site.urls),
]
# 创建数据库表
python3 manage.py makemigrations
python3 manage.py migrate
# 设置防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent #开启80端口
systemctl restart firewalld #重启防火墙
# 运行网站
python3 manage.py runserver 0.0.0.0:80 #监听机器上所有ip的80端口
安装 Apache 和 mod_wsgi
yum -y install httpd httpd-devel # 安装 apache 2.4 和它的开发包
yum -y install mod_wsgi -y # 安装 mod_wsgi 3.4
(未完)
更多推荐
已为社区贡献1条内容
所有评论(0)