1)Window安装和自然环境配备
在网上教程确实太多了 ,就已不描述 ,自主百度搜索
强烈推荐教程:https://www.cnblogs.com/vilee/p/10029675.html
2)Linux安装和自然环境配备
强烈推荐教程:https://blog.csdn.net/key_world/article/details/110214288
linux自然环境布署,碰到的一些小问题:
Q1:./configure --prefix=/usr/local/python3.9 编译程序安装出错得话
A1:sudo yum install gcc-c 查询是不是未安装适合的c语言编译器
Q2:实行make出現编号难题
A2:在./configure操作过程,先开展配备(etc/profile):
export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8
ps:这儿必须标明的是 ,在网上很多教程让立即把python删除掉,結果连yum命令也应用不了,以下
1、删除目前Python [root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制性删除已安装程序流程以及关系 [root@test ~]# whereis python |xargs rm -frv ##删除全部残留文档 ##xargs ,容许你对輸出实行别的一些指令 [root@test ~]# whereis python ##认证删除,回到无結果 2 、删除目前的yum [root@test ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps [root@test ~]# whereis yum |xargs rm -frv
处理:卸载掉centos内置python造成 yum命令无效的方式
https://blog.csdn.net/loveideality/article/details/81215440
3)python脚本实行依赖
python脚本运作依赖,pip list查询全部依赖
$ wget https://bootstrap.pypa.io/get-pip.py $ python get-pip.py $ pip -V #查询pip版本 $ pip install requests #requests包 $ pip install BeautifulSoup4 #BeautifulSoup4包
4)Java启用Python脚本编码
1 public List<Python> pythonUtils(String keyWord){ 2 Process proc; 3 String line = null; 4 ArrayList<Python> list = new ArrayList(); 5 try { 6 String[] arg1 = new String[]{"python","E:\\python\\Amazon.py" ,keyWord}; 7 proc = Runtime.getRuntime().exec(arg1); 8 //用I/O流来提取結果 9 BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), "utf-8")); 10 //创建对象要经try/catch里边 ,不然会没法接纳到for輸出每一个值 11 Python python = new Python(); 12 while ((line = in.readLine()) != null) { 13 String[] string1 = line.split("=="); 14 for (int i = 0; i <string1.length ; i ) { 15 String s = string1[i]; 16 //对获得脚本輸出的字符串数组开展字段名切分赋值 17 String[] string2 = s.split(","); 18 python.setShop(string2[0]); 19 python.setName(string2[1]); 20 python.setShop_yw(string2[2]); 21 list.add(python); 22 } 23 } 24 in.close(); 25 //脚本运作結果,0取得成功/1不成功 26 int status = proc.waitFor(); 27 System.out.println("Process exitValue: " status); 28 } catch (IOException e) { 29 e.printStackTrace(); 30 return null; 31 } catch (InterruptedException e){ 32 e.printStackTrace(); 33 return null; 34 }catch (ArrayIndexOutOfBoundsException e){ 35 e.printStackTrace(); 36 return null; 37 } 38 }