> ~/.termux/termux.p_termux换dns">
当前位置:   article > 正文

使用Termux配置Ubuntu Python开发环境_termux换dns

termux换dns

之前termux手册未下载完整版Linux,导致部分python功能用不了,比如opencv,折腾了好久都不成功。这里安装了一个只有31M的ubuntu,再安装opencv,so easy。配置如下:

termux配置

# 映射文件
termux-setup-storage
# 这里在termux home里建一个快捷方式
mkdir /sdcard/termux
ln -s /sdcard/termux ~/data

# 模拟root环境
# termux-chroot

# 更换国内源
termux-change-repo
apt update -y
apt upgrade -y

# 定制按钮
echo "extra-keys = [ \\" >> ~/.termux/termux.properties
echo " ['ESC','|','/','HOME','UP','END','PGUP','DEL'], \\" >> ~/.termux/termux.properties
echo " ['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN','BKSP'] \\" >> ~/.termux/termux.properties
echo "]" >> ~/.termux/termux.properties

# 支持蓝牙键盘输入
echo "enforce-char-based-input = true" >> ~/.termux/termux.properties

# 修改问候语
vim $PREFIX/etc/motd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

安装ssh访问

pkg install openssh -y
# 设置密码
passwd
# 启动ssh
sshd
ssh user@host -p 8022
# 杀死ssh
pkill sshd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

安装自动补全插件

# 安装常用工具
apt install vim git curl wget tree nmap zip -y

# 安装 zsh
apt install zsh -y
# 安装oh-my-zsh,及自动补全插件
# sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
git clone git://github.com/ohmyzsh/oh-my-zsh.git ~/.oh-my-zsh
git clone git://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
vim /data/data/com.termux/files/home/.oh-my-zsh/templates/zshrc.zsh-template
    export TERMUX_HOME=/data/data/com.termux/files
    export PATH=$PATH:$TERMUX_HOME/usr/bin:.
    export ZSH=$TERMUX_HOME/home/.oh-my-zsh
	plugins=(其他的插件 zsh-autosuggestions)
# 启用oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh -s zsh
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

安装ubuntu

# 安装ubuntu
apt install proot-distro -y
proot-distro install ubuntu
# 登录 ubuntu
proot-distro login ubuntu

# 配置oh-my-zsh, 复制上面配置配置好的即可
cp /data/data/com.termux/files/home/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh -s /data/data/com.termux/files/usr/bin/zsh

# 修改dns
echo 'nameserver 114.114.114.114' > /etc/resolv.conf
echo 'nameserver 8.8.8.8' >> /etc/resolv.conf

# 更换源
# https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu-ports/
cp /etc/apt/sources.list /etc/apt/sources.list.bak

echo 'deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ hirsute main restricted universe multiverse' > /etc/apt/sources.list
apt update -y
# 安装ca-certificates,以使用https
apt install ca-certificates -y

echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ hirsute main restricted universe multiverse' > /etc/apt/sources.list
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ hirsute-updates main restricted universe multiverse' >> /etc/apt/sources.list
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ hirsute-backports main restricted universe multiverse' >> /etc/apt/sources.list
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ hirsute-security main restricted universe multiverse' >> /etc/apt/sources.list
apt update -y
apt upgrade -y
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

安装python开发环境

apt install python3 python3-pip -y
python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install ipython -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装 jupyter
pip install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install jupyterlab -i https://pypi.tuna.tsinghua.edu.cn/simple

# 设置jupyter远程登录密码
# python
# from notebook.auth import passwd
# passwd()
jupyter notebook --generate-config
vim .jupyter/jupyter_notebook_config.py
	c.NotebookApp.password = '通过passwd()生成的密码'
	c.NotebookApp.allow_remote_access = True
	c.NotebookApp.ip='*'
	c.NotebookApp.open_browser = False
	# c.NotebookApp.port = 8888
	# c.NotebookApp.notebook_dir = "启动路径"

# 启动 notebook
nohup jupyter notebook --allow-root>/dev/null 2>&1 &

# 其他模块
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
# opencv依赖
apt install libgl1-mesa-glx -y 
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

vim相关

# 解决中文乱码
echo "set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1" >> ~/.vimrc
echo "set enc=utf8" >> ~/.vimrc
echo "set fencs=utf8,gbk,gb2312,gb18030" >> ~/.vimrc
# 显示行号
echo "set number" >> ~/.vimrc
source ~/.vimrc

# vim 粘贴不自动换行 
set paste
set nopaste
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

其他

# 安装adb
cd ~/
git clone https://github.com/Magisk-Modules-Repo/adb-ndk.git
cd ./adb-ndk/bin/
mv -f adb.bin adb
chmod +x ./*
mv -f ./* /data/data/com.termux/files/usr/bin/
cd ~/
rm -rf adb-ndk/

# 安装 uiautomator2
pkg install libxml2 libxslt libjpeg-turbo -y
pip install --pre uiautomator2

# 安装qemu
pkg install x11-repo
pkg install qemu-common qemu-system-x86_64 qemu-utils
# 启动qemu
#qemu-img create -f raw hd0.img 10G
#qemu-system-x86_64 -hda hd0.img -cdrom /sdcard/BaiduNetdisk/winxp.iso -m 2048 -netdev user,id=user.0 -device rtl8139,netdev=user.0 -vga vmware -display vnc=:10
qemu-system-x86_64 -hda /sdcard/BaiduNetdisk/winxp.img -m 4096 -netdev user,id=user.0 -device rtl8139,netdev=user.0 -vga vmware -display vnc=:10

# 安装logo工具
pkg install figlet
ls $PREFIX/share/figlet
figlet -f shadow 'UNIHOU'

 |   |  \  |_ _| |   |  _ \  |   | 
 |   |   \ |  |  |   | |   | |   | 
 |   | |\  |  |  ___ | |   | |   | 
\___/ _| \_|___|_|  _|\___/ \___/ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

备份与恢复

# 备份termux
cd /data/data/com.termux/files
tar -zcf /sdcard/termux/termux-backup.tar.gz home usr
# 恢复termux
termux-setup-storage
cd /data/data/com.termux/files
tar -zxf /sdcard/termux/termux-backup.tar.gz --recursive-unlink --preserve-permissions
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/393999?site
推荐阅读
相关标签
  

闽ICP备14008679号