1.Python环境搭建
1.1Python 安装
1.1.1下载python依赖
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
1.1.2下载源码包
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
1.1.3解压包
tar -zxvf Python-3.7.2.tgz
1.1.4 进入解压后的目录,编译安装
cd Python-3.7.2 ./configure --prefix=/opt/python37 make && make install
1.1.5 建立python3的软连接
\# python3.7.3软链接 ln -s /opt/python37/bin/python3 /usr/bin/python3 \# pip3软链接 ln -s /opt/python37/bin/pip3 /usr/bin/pip
1.1.6 将环境变量写入环境
[root@localhost ~]# vi .bash_profile [root@localhost ~]# source ~/.bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/bin/python3/bin export PATH 也可以下载etc/profile文件 [root@localhost conf]# cat /etc/profile PATH=/opt/python37/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
1.1.7 检查是否安装成功
[root@localhost Python-3.7.2]# python3 Python 3.7.2 (default, Apr 7 2023, 16:06:23) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information.
1.2 pip安装
1.1.1官网下载
PyPI · The Python Package Index 下载版本 pip-9.0.1.tar.gz
1.1.2 解压
tar -xzvf pip-9.0.1.tar.gz
1.1.3 安装
cd pip-9.0.1/ python3 setup.py install
1.1.4 建立软连接
ln -s /opt/python37/bin/pip3 /usr/bin/pip
1.1.5 验证是否安装成功
[root@localhost pip-9.0.1]# pip Usage: pip <command> [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. search Search PyPI for packages. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). --log <path> Path to a verbose appending log. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort. --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to alternate CA bundle. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index. [root@localhost pip-9.0.1]#
1.3 依赖包安装
pip install opencv-python==4.5.5.62