zoukankan      html  css  js  c++  java
  • 如何看一个python的模块是否安装了

    pip list

    pip freeze

    pip show <module_name>

    pip search <module_name>

    How to know if a python module is installed or not in the system: You can do a very easy test in terminal,

    $ python -c "import math"
    $ echo $?
    0                                # math module exists in system
    
    $ python -c "import numpy"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named numpy
    $ echo $?
    1                                # numpy module does not exist in system


    In case we do not want to unwantedly import a module in question (which would happen in a trystatement) we can make use of sys.modules to test modules that are installed and were imported before.

    In the python shell issue:

    >>> import sys

    Then test for installed modules:

    >>> 'numpy' in sys.modules
    True
    >>> 'scipy' in sys.modules
    False
     
  • 相关阅读:
    python函数
    文件操作
    python列表,元组,字典,集合简介
    python字符串(str)
    python数字类型 or 进制转换
    流程控制
    Python入门
    Python垃圾回收机制
    python简介&下载&安装
    DAY11
  • 原文地址:https://www.cnblogs.com/andy-0212/p/10198110.html
Copyright © 2011-2022 走看看