栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

安卓termux安装python、R和jupyter

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

安卓termux安装python、R和jupyter

手机:红米note9 pro :ROM:128GB、RAM:8GB、高通8核2.2GHz、安卓内核:4.19.81(MIUI 12.0.11)

  1. 安装termux/aid learing(华为开发的):

     Termux只是一个Android的终端模拟器,安装在数据区prefix的一套类似GNU/Linux的命令行工具,加上一套基于Debian发展出来的软件包管理器.它不带C标准库,而是使用的Android NDK的C标准库,跟GNU/Linux。
     
     (1)下载安装:
     手机浏览器打开https://termux.com/
     点击get it on F-Droid图标,进入https://f-droid.org/packages/com.termux/
     下载最新版的APK文件(不是F-DROID)
     安装未知,未签名软件;
     (2)基础配置:
     打开termux后输入:termux-change-repo后进入软件源选择图形界面,使用空格和回车选择清华源;
     打开github.com(将其ip放入host访问!)搜索gcc_termux,打开后按说明文件设置:
     	vi $PREFIX/etc/apt/sources.list 						#vi编辑器打开sources.list文件
     	i																		#进入编辑模式
     	deb https://its-pointless.github.io/files/24  termux extras		#将此地址添加在最下面
     	:																		#进入命令模式
     	wq																	#保存并退出
      	cd $PREFIX/etc/apt/
      	wget https://its-pointless.github.io/pointless.gpg		#下载key文件
      	apt-get install gnupg										
      	apt-key add pointless.gpg									#载入key文件
      	apt-get update														#更新源
     输入termux-setup-storage后允许开启访问手机存储
    
  2. 安装ssh协议,用于电脑控制termux
    pkg upgrade && pkg update #源库文件升级和系统更新
    pkg install openssh #安装ssh服务
    ip a #查看termux的ip
    whoami #查看termux当前用户名
    passwd username #设置当前用户密码
    ps aux | grep sshd #查看ssh服务是否在进程中
    ssh localhost -p 8022 #开启ssh服务,端口为8022(默认也为8022)
    在电脑端xshall中输入termux的ip、用户名、密码和端口信息,点击登录即可访问手机termux;有时手机黑屏后会连接变慢。

  3. 安装常用软件:
    apt install git cmake wget curl vi zip unzip tar clang proot #cmake是c编译器,clang是c/c++库,proot是一个无需root权
    限就能执行 chroot操作的工具(使用termux_chroot命令)。用于在
    ubuntu里模拟需要sudo的权限(否则没法安装软件)。

  4. 安装python:(aid learing自带python,但aid learning太占手机内存和空间!且独立于手机的系统!)
    apt install python2 python3 #这个很顺利,默认分别安装最高版,同时安装对应的pip2(19.2.3)和pip3,python2在部分包安装时有用!
    python2 -m pip install --upgrade pip #这两条命令分别升级了pip2和pip3到最新版.(这里建议先不要升级pip2,有些包对新版不兼容!)
    python -m pip install --upgrade pip #这两条命令分别升级了pip2和pip3到最新版.
    pip install requests beautifulsoup4 libxml2 libxslt libffi wheel #安装python依赖第三方库
    pip install lxml #安装lxml模块
    apt install gcc-9 rust #需要用到github的源,可以使用apt search gcc、rust来确定可以安装的版本,而不
    只是gcc-7等,目前已到gcc-11;然后运行setupclang-gfort-11命令,提示now using
    clang as default compiler with gfortran-11;

     														#gcc在编译cryptography时使用!
     														#Rust 是一种系统编程语言。 它有着惊人的运行速度,能够防止段错误,并保证线程安全。
     pip2 install cryptography					#只能用pip2安装,pip3报错!耐心!
     pip install scrapy                             #到这里才能成功安装scrapy!耐心!
     pip3 install cython							#cython包安装
     apt install numpy								#使用pip安装会报错,使用github源安装!
     pip install matplotlib     					#安装上述2个包后才能安装它。
    
  5. 安装R及R包:
    pkg install r-base #相对顺利
    apt-get install make libtiff libcairo librsvg #有些包编译需要
    进入R后输入:install.packages(‘ggplot2’) #报错,目前无法安装!找不到gfortran

  6. 安装jupyter
    apt install nodejs
    pip install npm # absence of this causes non-editable cells in jupyter,apt install cannot find this packages.
    apt install gfortran
    apt install liblapack-dev #没有此文件
    apt install libopenblas-dev #没有此文件
    pip install jupyter #安装python和R后安装,没有报错,顺利!

  7. jupyter安装R内核
    IRkernel依赖包的安装:‘digest’, ‘base64enc’, ‘rlang’, ‘fastmap’,‘htmltools’,‘ellipsis’, ‘glue’,‘vctrs’,‘fansi’, ‘lifecycle’, ‘utf8’, ‘jsonlite’, ‘pillar’可以安装,但 由于’cli‘安装出现错误(

 thread.c:29:3: warning: implicit declaration of function
     				 'pthread_setcanceltype' is invalid in C99 [-Wimplicit-function-declaration]
 					 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
					  ^
						thread.c:29:25: error: use of undeclared identifier
     				 'PTHREAD_CANCEL_ASYNCHRONOUS'
  						pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old);
                        ^
						thread.c:80:11: warning: implicit declaration of function
     					 'pthread_cancel' is invalid in C99 [-Wimplicit-function-declaration]
  					  ret = pthread_cancel(tick_thread);
       					   ^
						2 warnings and 1 error generated.
						make: *** [/data/data/com.termux/files/usr/lib/R/etc/Makeconf:168: thread.o] Error 1
							make: *** Waiting for unfinished jobs....
						ERROR: compilation failed for package ‘cli’
						)
	因此‘repr’, ‘IRdisplay’, ‘pbdZMQ’, ‘jsonlite’, ‘uuid’,无法安装!
  1. install.packages(“IRkernel”): 目前无法安装!只能安装Vim和vim-plug(Nvim-R)
    IRkernel::installspec() # 只在当前用户下安装;
    IRkernel::installspec(user = FALSE) # 在系统下安装
    q()

     安装vim:  apt install vim nvim    		#vim程序安装目录:/data/data/com.termux/files/vim
     安装vim-plug:   mkdir -p  ~/.vim/autoload/
     							输入:curl -fLo ~/.vim/autoload/plug.vim --create-dirs 
     									    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
     										# 从以下github连接下载vim-plug
     							vim ~/.vimrc      #创建.vimrc文件并添加以下内容
     										call plug#begin('~/.vim/plugged')					#(内的内容是集中放置plug的地方)
     										Plug 'jalvesaq/Nvim-R'
     										call plug#end()
     					        			按Esc,进入命令行模式输入
     					        			:source .vimrc					#vim编辑器引入上述变量
     					        			:PlugInstall						#vim编辑器开始调用vim-plug安装环境变量中的插件,等待
     					        			:q!
     运行:命令行输入vim 1.R
     			进入后,在?模式下直接输入rf(上下双窗口模式)或	ro(Rstudio三窗口模式) 等待Nvim-R的载入;
     			vim里不同窗口的切换用 ctrl + w + h/j/k/l
     			输入rq关闭终端,如果不小心输入:q!则直接退出vim并进入了R语言,需要输入quit()来退出R;
     			当你能打开如上界面之后,那么我们可以学习一些常用操作了,如下:
     				    执行当前文件的所有代码: aa
     				    执行整个函数: ff
     				    执行所选内容: ss
     				    执行当前行: l
     				    还可以像Rstudio一样查看数据库中的内容,在对象上输入rv, 在Linux上需要先安装插件"chrisbra/csv.vim"
     				    代码补全依赖于一个更好的工具ncm-R, 但是安装起来特别的费劲,花了一个下午的时间都没有搞定,所以我放弃了。
    

参考:
https://blog.csdn.net/weixin_39956612/article/details/110698934 termux安装python2_termux怎么安装python
https://www.bilibili.com/read/cv3804689/
http://hdevin.cn/articles/28.html #Termux 安装 Linux 以及搭建 Python 运行环境;这个较好!
https://github.com/its-pointless/gcc_termux/blob/4330e34382fa57215321287ebc005a9ce3394947/README.txt
https://stackoverflow.com/questions/36968411/installing-r-on-android#:~:text=Installing%20R%20on%20Android.%201%20Step%201%3A%20Install,R%20by%20typing%20an%20upper%20case%20R.%20 Installing R on Android
https://tteoh.com/post/2016-10-20-r-rstudio-mobile-android/ Running R and RStudio from an Android mobile phone or tablet
https://www.bilibili.com/read/cv3804689/ 安卓手机Python和R语言环境配置!
https://conr.ca/post/installing-r-on-android-via-termux/ Installing R on Android via Termux
https://github.com/jalvesaq/Nvim-R Nvim下载连接
https://github.com/junegunn/vim-plug vim-plug下载地址,vim安装插件主要参考
https://www.cnblogs.com/ziwuxian/p/12922439.html vim安装插件主要参考
https://www.jianshu.com/p/76931cea074c vim操作参考
https://www.vim.org/scripts/script.php?script_id=2628 Nvim-R插件下载
https://www.sqlsec.com/2018/05/termux.html?from=groupmessage#toc-heading-38 #较全面的Termux 高级终端安装
使用配置教程
https://conr.ca/post/installing-r-on-android-via-termux/ #部分参考

========================================================================================================termux安装Ubuntu LTS(由于termux安装R包时gcc冲突,且无法安装devtools,果断安装ubunt)=
安装方法见:
https://github.com/MFDGaming/ubuntu-in-termux 安装方法,原始地址
源更改:
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=21.04
DISTRIB_CODENAME=hirsute
DISTRIB_DEscriptION=“Ubuntu 21.04”

https://blog.csdn.net/weixin_45579994/article/details/114063703 arm源的说明;

https://developer.aliyun.com/mirror/ubuntu-ports?spm=a2c6h.13651102.0.0.3e221b11hPdrud 阿里ubuntu-port源地址
参照上面的说明,本人自己总结的一下源地址:
sed -i ‘s/原始信息/新的替换信息/g’ /etc/apt/source.list

deb https://mirrors.aliyun.com/ubuntu-ports/ hirsute-security main restricted
 # deb-src https://mirrors.aliyun.com/ubuntu-ports/ hirsute-security main restricted
deb https://mirrors.aliyun.com/ubuntu-ports/ hirsute-security universe
 # deb-src https://mirrors.aliyun.com/ubuntu-ports/ hirsute-security universe
deb https://mirrors.aliyun.com/ubuntu-ports/ hirsute-security multiverse
 # deb-src https://mirrors.aliyun.com/ubuntu-ports/ hirsute-security multiverse

切记是https!!

Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown.报错的解决:参考https://blog.csdn.net/Moolight_shadow/article/details/119511642 》》》》运行
touch /etc/apt/apt.conf.d/99verify-peer.conf && echo >>/etc/apt/apt.conf.d/99verify-peer.conf "Acquire { https::Verify-Peer false }"

aid_learning安装及配置

  1. 红米note9pro,商店直接安装aid learning即可。
  2. 打开后注册,进入,自动联网安装完全版,并进入界面。
  3. 更改源,vim etc/apt/sources.list文件,参见https://mirrors.tuna.tsinghua.edu.cn/help/debian/
  4. R的安装,apt install r-base
  5. 安装ggplot2包,进入R后,install.packages(‘ggplot2’),就能自动安装。
  6. 安装IRKernel,进入R后输入install.packages(“IRkernel”),自动安装,继续输入IRkernel::installspec(user=FALSE),然后q()退出R。
  7. 打开桌面的jupyter notebook就能写python和R的脚本了。
  8. w无法访问sdcard目录的原因就是没有开启aid learning的完全访问权限。
  9. jupyter notebook默认工作目录的修改:

官网教程里有更多其他详细设置说明。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/296112.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号