https://blog.csdn.net/phs999/article/details/79218869

pyhton 安装pip 以及 numpy (解决python:ModuleNotFoundError:No module named "numpy" 等类似缺包问题

2018年01月31日 16:24:43 phs999 阅读数:11177 标签: python 更多

个人分类: Python

总的解决思路就是用pip命令安装缺少的包(库)。假定python中已经默认安装了pip命令,假如我缺少numpy包的话,在cmd中python3执行:

pip3 install numpy

pyhton2的话执行:

pip install numpy

如果提示不能执行pip命令或pip命令没有安装,则进行下面的pip安装操作后,再进行上面的安装包的操作。

在安装了基本python环境后,浏览器打开下列网址,右键-另存为get-pip.py。保存到python安装目录,如:“C:\Python36”

https://bootstrap.pypa.io/get-pip.py

然后双击执行本地的get-pip.py文件(或者打开cmd,执行python get-pip.py).

安装完毕后,可使用pip命令安装相应的包。

由此解决了 
python:ModuleNotFoundError:No module named “numpy”问题。 
其他类似问题用pip安装相应的包即可。

1---------------------------------------

import java.awt.*;
import java.io.*;
import javax.swing.*;

public class ImageViewer 
{
    public static void main(String[] args) 
    {
        EventQueue.invokeLater(() -> 
        {
            JFrame frame = new ImageViewerFrame();
            frame.setTitle("手写识别系统");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        });
    }
}

class ImageViewerFrame extends JFrame
{
    private JLabel label;
    private JFileChooser chooser;
    private static final int DEFAULT_WIDTH = 600;
    private static final int DEFAULT_HEIGHT = 768;

private void welcomePage() 
    {
        ImageIcon icon = new ImageIcon("./welcomePage.jpg");
        icon.setImage(icon.getImage().getScaledInstance(DEFAULT_WIDTH, DEFAULT_HEIGHT, Image.SCALE_DEFAULT));
        label.setIcon(icon);
    }

private void initOptionPane()
    {
        UIManager.put("Label.font", new Font("Dialog", Font.PLAIN, 78));
    }

private String getAnswer(String path)
    {
        PyCaller.writeImagePath(path);
        PyCaller.execPy();
        return PyCaller.readAnswer();
    }

public ImageViewerFrame()
    {
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        setLocationRelativeTo(null);

// use a label to display the images
        label = new JLabel();
        add(label);

// set up the file chooser
        chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File("."));

// set up the menu bar
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

JMenu menu = new JMenu("File");
        menuBar.add(menu);

JMenuItem openItem = new JMenuItem("Open");
        menu.add(openItem);

welcomePage();

openItem.addActionListener(event -> {
            // show file chooser dialog
            int result = chooser.showOpenDialog(null);

// if file selected, set it as icon of the label
            if (result == JFileChooser.APPROVE_OPTION) {
                String path = chooser.getSelectedFile().getPath();
                ImageIcon icon = new ImageIcon(path);
                icon.setImage(icon.getImage().getScaledInstance(DEFAULT_WIDTH, DEFAULT_HEIGHT, Image.SCALE_DEFAULT));
                label.setIcon(icon);

// my codes
                initOptionPane();
                String answer = getAnswer(path);
                JOptionPane.showMessageDialog(null, "识别结果:" + answer + " ");
            }
        });

JMenuItem exitItem = new JMenuItem("Exit");
        menu.add(exitItem);
        exitItem.addActionListener(event -> System.exit(0));
    }
}

---------------------------------------

2

import java.io.*;

class PyCaller
{
    private static final String DATA_SWAP = "temp.txt";
    private static final String PY_URL = System.getProperty("user.dir") + "\\test.py";

public static void writeImagePath(String path)
    {
        PrintWriter pw = null;
        try
        {
            pw = new PrintWriter(new FileWriter(new File(DATA_SWAP)));
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

pw.print(path);
        pw.close();
    }

public static String readAnswer() 
    {
        BufferedReader br;
        String answer = null;
        try 
        {
            br = new BufferedReader(new FileReader(new File(DATA_SWAP)));
            answer = br.readLine();
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

return answer;
    }

public static void execPy() 
    {
        Process proc = null;
        try
        {
            System.out.println(System.getProperty("user.dir") + "\\test.py");
            // proc = Runtime.getRuntime().exec("ipython3 " + PY_URL);
            proc = Runtime.getRuntime().exec("python " + PY_URL);
            proc.waitFor();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        } 
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
    }

public static void main(String[] args) throws IOException, InterruptedException 
    {
        writeImagePath("D:\\labs\\Yao\\test.jpg");
        execPy();
        System.out.println(readAnswer());
    }
}

3-----------------------------------------------

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test 
{

public Test()
    {
        
    }
    
private static String filePathTxt = "C:\\workspace\\JAVAAndPython\\temp2.txt";
    
    public static String readAns()
    {
        String str = "";
        BufferedReader br;
        String answer = null;
        try
        {
            br = new BufferedReader(new FileReader(new File(filePathTxt)));
            answer = br.readLine();

//  String regEx = "count(\\d+)(df)";  
            String regEx1 = "([1-9a-zA-Z]+)\\$\\$\\$([1-9a-zA-Z]+)\\$\\$\\$([1-9a-zA-Z]+)\\$\\$\\$\\$([1-9a-zA-Z]+)\\$\\$([1-9a-zA-Z]+)\\$\\$\\$";  
           
          //  String regEx = "([1-9a-zA-Z]+)\\$\\$\\$";
           // answer = "111$$$";
            Pattern pat = Pattern.compile(regEx1);  
            Matcher mat = pat.matcher(answer);  
            if(mat.find())
            {
                 System.out.println(mat.group(0));
                 System.out.println(mat.group(1));
                 System.out.println(mat.group(2));
                 System.out.println(mat.group(3));
                 System.out.println(mat.group(4));
                 System.out.println(mat.group(5));
            }
            else
            {
                   System.out.println("-----not match");
            }
    
        }
        catch (FileNotFoundException e) 
        {
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }

return answer;

}
    public static void main(String[] args)
    {
        readAns();
    }

}

pyhton 安装pip 以及 numpy (解决python:ModuleNotFoundError:No module named numpy 等类似缺包问题相关推荐

  1. 解决运行python脚本报错:ModuleNotFoundError: No module named ‘numpy‘

    报错: Traceback (most recent call last):   File "get_kpi.py", line 2, in <module>     ...

  2. 已安装各个模块,程序仍报错:ModuleNotFoundError: No module named 'numpy'

    对于已安装各个模块的如numpy.pandas.jupyter notebook等,程序仍报错:ModuleNotFoundError: No module named 'numpy' 我当时还怀疑自 ...

  3. 解决ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath‘ 错误

    解决ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' 错误 文章目录: 一.错误原因分析 二.解决方式 调试了好久 ...

  4. 成功解决运行tensorflow时ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath‘

    成功解决运行tensorflow时ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' 目录 解决问题 解决思路 解决 ...

  5. python ModuleNotFoundError: No module named ‘frontend‘

    今天在pdf转换为图片的时候,出现了下面的错误: ➜ OCR_table python pdf_to_image.py Traceback (most recent call last):File & ...

  6. python ModuleNotFoundError: No module named ‘requests‘ 的 解决方案

    python ModuleNotFoundError: No module named 'requests' 的 解决方案 参考文章: (1)python ModuleNotFoundError: N ...

  7. python ModuleNotFoundError: No module named ‘config

    通过命令行执行报错:ModuleNotFoundError: No module named 'config' 命令行执行存在该问题 关于以上问题是因为:执行文件pytest_demo里面import ...

  8. 解决:ModuleNotFoundError: No module named 'XXX' (全)文件路径目录没错的情况下请不要重名

    转载于:https://blog.51cto.com/2338053/1982977 一.背景介绍 1. 工具目录结构 为了便于统一管理一些小工具,在本地创建了一个mytools的目录,子目录的结构如 ...

  9. 引用安装好的pywin,出现“ModuleNotFoundError: No module named 'win32api'”提示

    第一步:pywin32 下载链接:https://sourceforge.net/projects/pywin32/ 在file菜单下找到符合自己安装版本,我是python3.7,win64 位,下载 ...

最新文章

  1. Java项目:酒店管理系统(java+Springboot+Mybatis+Beetl+Layui)
  2. Android Apt失效:找不到Apt生成的对应类
  3. 面试官:你知道哪几种事务失效的场景?
  4. HttpClient在传参和返回结果的中文乱码问题
  5. 对爬虫爬取到的数据进行存储
  6. get,post请求的编码统一
  7. cam350 不能打开光绘文件_CAM350使用教程-复制Gerber层
  8. Word——目录显示和标题样式设置
  9. PJzhang:微软出口管制条例
  10. 音频测量常见的校准原理 ADC灵敏度校准 DAC频率响应校准 麦克风校准 Soundcheck软件校准
  11. HTTPS证书转换成PEM格式
  12. Navicat Premium for Mac破解教程
  13. 什么是物联网网关及其主要特点
  14. Node之Express服务器启动安装与配置
  15. 为什么老是把词语读反_为什么孩子总是会把字母、数字给写反?这里有妙招!...
  16. Postman高级应用(5):再也不用注释签名代码了——自动生成签名
  17. 17 记一次 spark 读取大数据表 OOM OutOfMemoryError: GC overhead limit exceeded
  18. linux 在线和离线安装Mplayer视频播放器
  19. 企业工商信息查询接口
  20. VC中使用自定义资源

热门文章

  1. 加密解密_使用RSA密钥对加密解密数据
  2. 基于ip地址的客户识别原理_使用 LVS 实现负载均衡原理及安装配置
  3. mediarecorder添加时间戳_[Paper] 自动驾驶中相机和激光雷达的时间戳误差标定
  4. android+tv+自动切换,Android TV 重写GridView,实现焦点放大效果
  5. 自定义LayoutManager实现最美应用列表
  6. 8款帅酷的HTML5/CSS3 3D动画、图片、菜单应用
  7. 自动化部署之jenkins
  8. atitit. 文件上传带进度条 atiUP 设计 java c# php
  9. 【转】iOS开发-Protocol协议及委托代理(Delegate)传值
  10. python 进程池pool简单实例