上一篇介绍了如何将一台旧手机打造成一台云服务器,让任何人都能访问你手机上部署的网站。
但是在实际上当我去找一个开源项目来部署的时候,还是遇到不少坑的,花了挺长时间,才好不容易跑成功。所以这一篇单独来介绍在手机上部署一个现成的开源博客站项目,主要是帮大家避坑,可以顺利部署一个博客站。
我们来部署下这个开源博客系统,python django框架
下载地址:https://gitee.com/lylinux/DjangoBlog.git
第一大坑
Python版本,永远的痛!!!
因为我安装的是最新版的termux,所以默认安装python的时候没有选择版本,所以用的是 python 3.10.6 这个版本,按照项目部署教程来,环境安装这一步就卡住了。。。。
安装项目环境
主要遇到的有两类问题:
- 缺少系统库文件
- 缺少python依赖库
系统库文件指的是linux系统上的底层库,比如binutils、openssl、openssh等;
python依赖库指的是python程序运行时依赖库文件,比如flask、django等;
但是即便是该安装的安装了,最后还是失败,卡在了一个gevents的编译问题,始终绕不过,查阅了网上能尝试的手法,最终有人说将python的版本进行降级,降到3.8版本。
于是开始尝试卸载当前版本,去安装3.8版本,安装好后去编译又遇到其他问题,没有找到解决方案。
于是死马当活马医(快要放弃了),又尝试了3.9版本,也提示了一大堆报错信息,挨个去解决,最终发现3.9的版本可以将这个博客站项目编译通过,并正确运行起来,中间的坑太多,也趟了过来!
第二大坑
手机上python3.9版本哪里去找
下面这个地址给大家提供了各个系统版本的python,可以直接用,很爽!
https://github.com/Termux-pod/termux-pod
termux-pod
我这里选择是aarch64版本下的python环境:
因为提供的是deb安装包,可以用下面的命令来安装
dpkg -i python_3.9.7_aarch64.deb
安装成功后,就可以看到python环境已经是3.9的了,可以继续往下。
第三大坑
该装的环境一个都少不了!!!
使用python 3.9来编译还是绕不开安装系统库和python依赖库的问题,总结了以下遇到的错误以及解决方案:
错误 1: 安装python依赖库失败
Could not fetch URL https://pypi.org/simple/flask/:
There was a problem confirming the SSL certificate: HTTPSConnectionPool(
host='pypi.org', port=443): Max retries exceeded with
url: /simple/flask/
(Caused by SSLError("Can't connect to HTTPS URL because the
SSL module is not available.")) - skipping
解决:切换下载的安装源
# 安装的时候加上 -i参数,参数后加上可信任的源下载地址
pip install xxxxxxx
-i http://pypi.douban.com/simple --trusted-host pypi.douban.com
错误 2: 安装mysql_client库失败
ERROR: Command errored out with exit status 1:
command: /data/data/com.termux/Files/usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/data/data/com.termux/files/usr/tmp/pip-install-w0p9f7ii/mysqlclient_9c417fb6071548a6a9f9fbba4c3929b5/setup.py'"'"'; __file__='"'"'/data/data/com.termux/files/usr/tmp/pip-install-w0p9f7ii/mysqlclient_9c417fb6071548a6a9f9fbba4c3929b5/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /data/data/com.termux/files/usr/tmp/pip-pip-egg-info-w5nq7rvj
cwd: /data/data/com.termux/files/usr/tmp/pip-install-w0p9f7ii/mysqlclient_9c417fb6071548a6a9f9fbba4c3929b5/
Complete output (10 lines):
/data/data/com.termux/files/usr/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/data/data/com.termux/files/usr/tmp/pip-install-w0p9f7ii/mysqlclient_9c417fb6071548a6a9f9fbba4c3929b5/setup.py", line 17, in <module>
metadata, options = get_config()
File "/data/data/com.termux/files/usr/tmp/pip-install-w0p9f7ii/mysqlclient_9c417fb6071548a6a9f9fbba4c3929b5/setup_posix.py", line 47, in get_config
libs = mysql_config("libs_r")
File "/data/data/com.termux/files/usr/tmp/pip-install-w0p9f7ii/mysqlclient_9c417fb6071548a6a9f9fbba4c3929b5/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
解决:先安装其他依赖库
# 先安装这个库
pkg install mariadb
错误 3: 安装pillow库失败,缺少jpeg系统库文件
The headers or library files could not be found for jpeg,
a required dependency when compiling Pillow from source.
Please see the install instructions at:
https://pillow.readthedocs.io/en/latest/installation.html
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/tmp/pip-install-pcl3slt4/pillow_ea8b4006d54e41989e54a98fdd6ac8f5/setup.py", line 989, in <module>
setup(
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/command/install.py", line 546, in run
self.run_command('build')
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 79, in run
_build_ext.run(self)
File "/data/data/com.termux/files/usr/lib/python3.9/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/data/data/com.termux/files/usr/tmp/pip-install-pcl3slt4/pillow_ea8b4006d54e41989e54a98fdd6ac8f5/setup.py", line 804, in build_extensions
raise RequiredDependencyexception(f)
__main__.RequiredDependencyException: jpeg
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/data/data/com.termux/files/usr/tmp/pip-install-pcl3slt4/pillow_ea8b4006d54e41989e54a98fdd6ac8f5/setup.py", line 1009, in <module>
raise RequiredDependencyException(msg)
__main__.RequiredDependencyException:
The headers or library files could not be found for jpeg,
a required dependency when compiling Pillow from source.
Please see the install instructions at:
https://pillow.readthedocs.io/en/latest/installation.html
解决:
# 先安装下面d系统库
pkg install openjpeg
pkg install libjpeg-turbo
错误 4: 运行开源博客站的时候,缺少库
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tzdata'
解决:
# 安装python依赖库
pip install tzdata -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
闯关成功
经过上面的步骤,我们的python环境就安装成功了,剩下的步骤只要按照博客站的要求来就能轻松部署成了。