1介绍
主要是自己使用的时候,方便查找,整理一下,都是自己使用过的
2python
- 下载Python压缩包
到Python官网下载Python 3.9.9压缩包:
- 文件上传并解压
# 2.1 首先到根目录,在/usr/local目录下创建python目录
[root@bogon home]# cd /
[root@bogon /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
[root@bogon /]# cd usr
[root@bogon usr]# ls
bin etc games include lib lib64 libexec local sbin share src tmp
[root@bogon usr]# ls local
bin etc games include lib lib64 libexec sbin share src
[root@bogon usr]# cd local
[root@bogon local]# ls
bin etc games include lib lib64 libexec sbin share src
[root@bogon local]# mkdir python
# 2.2 将python压缩包移动到/usr/local/python目录下,进行解压
[root@bogon Downloads]# mv Python-3.9.9.tar.xz /usr/local/python
[root@bogon Downloads]# cd /
[root@bogon /]# cd usr
[root@bogon usr]# cd local
[root@bogon local]# ls
bin etc games include lib lib64 libexec python sbin share src
[root@bogon local]# ls python
Python-3.9.9.tar.xz
[root@bogon local]#
[root@bogon local]# cd python
[root@bogon python]# tar xvf Python-3.9.9.tar.xz
Python-3.9.9/
Python-3.9.9/Python/
Python-3.9.9/Python/pystrtod.c
Python-3.9.9/Python/importlib.h
Python-3.9.9/Python/Python-ast.c
Python-3.9.9/Python/hamt.c
Python-3.9.9/Python/bltinmodule.c
Python-3.9.9/Python/context.c
Python-3.9.9/Python/future.c
Python-3.9.9/Python/pystrcmp.c
Python-3.9.9/Python/symtable.c
- 准备编译环境
到根目录下执行命令:
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
[root@bogon python]# cd /
[root@bogon /]# 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
- 编译安装
执行命令:
./configure --prefix=/usr/local/python/Python-3.9.9
[root@bogon /]# cd usr/local/python
[root@bogon python]# cd Python-3.9.9
[root@bogon Python-3.9.9]# ./configure --prefix=/usr/local/python/Python-3.9.9
接下来两步,直接即可:
make
make install
出现这么几行
Installing collected packages: setuptools, pip
。。。
Successfully installed pip-21.2.4 setuptools-58.1.0
- 配置环境变量
使用vim /etc/profile查看环境变量,
[root@bogon Python-3.9.9]# cd /
[root@bogon /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
[root@bogon /]# vim /etc/profile
打开之后,可能会出现这样,这步做起来,感觉好麻烦
While opening file "/etc/profile"
dated: Sun Nov 6 01:19:35 2016
(1) Another program may be editing the same file. If this is the case,
be careful not to end up with two different instances of the same
file when making changes. Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /etc/profile"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/.profile.swp"
to avoid this message.
Swap file "/etc/.profile.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
然后添加如下代码:
export PYTHON_HOME=/usr/local/python/Python-3.9.9
export PATH=$PYTHON_HOME/bin:$PATH
添加之后,:wq保存并退出
刷新环境变量的配置使其生效:source /etc/profile
6.大功告成
使用python3 -V #V为大写查看Python的版本信息,正是需要的Python3.7.5。
[root@bogon /]# source /etc/profile
[root@bogon /]# python3 -V
Python 3.9.9
最后将pip3也链接到/usr/bin下 可以快捷的使用命令
直接输如pip3 -V可以看到:
[root@bogon /]# pip3 -V
pip 21.2.4 from /usr/local/python/Python-3.9.9/lib/python3.9/site-packages/pip (python 3.9)
执行下面的命令,好像没什么用
[root@bogon /]# ln -s /usr/local/python/Python-3.9.9/lib/python3.9/site-packages/pip /usr/local/bin/pip3
[root@bogon /]# pip3 -V
pip 21.2.4 from /usr/local/python/Python-3.9.9/lib/python3.9/site-packages/pip (python 3.9)
运行python文件,直接找到py文件的目录,直接输入:python 文件名.py
2.2python文件打包成linux可执行文件
[root@bogon /]# pip3 install pyinstaller
[root@bogon /]# pyinstaller --version
4.7
打包
[root@bogon /]# cd home/123456
[root@bogon 123456]# ls
Desktop Downloads Pictures Templates Videos
Documents Music Public textClassify
[root@bogon 123456]# cd textClassify
[root@bogon textClassify]# ls
app.py mysqlClf.py server.py textClassifyData
[root@bogon textClassify]# pyinstaller -F -w server.py
89 INFO: PyInstaller: 4
。。。出错了
OSError: Python library not found: libpython3.9.so.1.0, libpython3.9m.so.1.0, libpython3.9.so, libpython3.9m.so, libpython3.9mu.so.1.0
This means your Python installation does not come with proper shared library files.
This usually happens due to missing development package, or unsuitable build parameters of the Python installation.
* On Debian/Ubuntu, you need to install Python development packages:
* apt-get install python3-dev
* apt-get install python-dev
* If you are building Python by yourself, rebuild with `--enable-shared` (or, `--enable-framework` on macOS).
需要先把文件的依赖包下载下来
1)如果是Ubuntu,按照指示,先看一下python3-dev有没有装,如果没有则
yum install python3-devel
反之下一步:
检查libpython3.6有没有装
然后重新进入python3.6安装路径:/usr/local/python/Python-3.9.9,rebuild一下:
rebuild
重新编译python,顺便打开ssl,避免以后掉坑
./configure --prefix=/usr/local/python --enable-shared --with-ssl
make
make install
居然还是报找不到so,http://www.cnblogs.com/trasin/p/6212124.html
查看动态库情况
ldd /usr/local/python36/bin/python3
把需要的.so复制到lib目录
cp libpython3.6m.so.1.0 /usr/lib64/
再次打包,这下可以了。这种环境问题真是够烦的
pyinstaller -F app.py
不行!不行!不行!来来回回折腾好几次,上网搜解决方法,不知道哪个解决的,反正又配置一遍,就好了
再试一下
pyinstaller -F 文件名.py
运行 ./文件名
好像还会报jieba/dict.txt什么错
pyinstaller打包(示例代码)
可以在windows下找到jieba目录下的dict.txt文件
在自己的项目目录下创建一个目录,将dict.txt复制进去
然后敲命令:
pyinstaller -F server.py --add-data="jieba/dict.txt:jieba"
注意:linux下是冒号,windows下是分号
打包之后,运行,使用命令 ./server
无法连接到本地服务器的解决方法如下:
2.3在Linux端安装sklearn,只需要用pip安装numpy/scipy/sklearn即可。
在安装scipy之前,要先安装numpy
命令:python3 -m pip install 【projectName】
命令1:python3 -m pip install numpy
命令2:python3 -m pip install scipy
命令3:python3 -m pip install scikit-learn
需要安装什么,可以去PYPI(https://pypi.org/)上,直接搜索
参考连接
CentOS7安装Python3环境:https://www.cnblogs.com/sgh1023/p/11688629.html