Python Basics 10 (module and package libraries installation use)

Source: Internet
Author: User

(1) using the standard library
#标准库: The function modules and packages provided in the Python installation package
Mainly include
Built-in types and functions
#比如len, int, open, etc.
#直接使用, no import required

Function module
#包含程序设计所需的常用的功能
#需要用import导入他们就可以使用

Import time
Print (Time.strftime ("%y_%m_%d%h:%m:%s"))

#打印结果如下
2018_06_17 11:06:16

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

#调用外部的计算器程序, just yo import OS operation library OS
Import OS
Os.system ("Calc")

Note: You need to know more functions and functions to view documents.

(2) Module search rules
#用import或者from ... import when importing a module, Python is determined by the list value of a variable content Sys.path of the Sys module.
>>> Import OS
>>> os.__file__
' c:\\users\\asus\\appdata\\local\\programs\\python\\python36\\lib\\os.py '
>>> Import Sys
>>> Sys.path
[' ', ' c:\\users\\asus\\appdata\\local\\programs\\python\\python36\\python36.zip ',
' C:\\users\\asus\\appdata\\local\\programs\\python\\python36\\dlls ',
' C:\\users\\asus\\appdata\\local\\programs\\python\\python36\\lib ',
' C:\\users\\asus\\appdata\\local\\programs\\python\\python36 ',
' C:\\users\\asus\\appdata\\local\\programs\\python\\python36\\lib\\site-packages ']

And the value of Sys.path is the Python interpreter. The following path is typically added to the Sys.path in the boot process.
1, the directory where the startup script is located;
2. Pythonpath the directory contained in the environment variable. Ignored if no settings are set. The environment variable setting and the PATH environment variable are set up in a similar way;
3, the standard library directory, has been with the installation of Python into the computer's lib/site-packages directory;
4. Lib/site-package the path specified in the. path file below.

Above is the Python interpreter START process automatically get the search path, we can also modify the contents of the Sys.path, dynamic change module search path.

-----------------------------------------------------------------------------
#比如我们搜索os模块的路径
>>> Import OS
>>> os.__file__
' c:\\users\\asus\\appdata\\local\\programs\\python\\python36\\lib\\os.py '

Custom Modules
If not in the current working directory
Can be added to Pythonpath.
Can also be written directly into Sys.path

(3) Pip install third-party library
Differences between third-party libraries and standard libraries: not built-in after the interpreter is installed.
After installation, the way it is imported is not the same as the standard library and the library you have developed.

#zhi安装方式:
#1, download, copy to the project catalog below
#2, official source PyPI (Python package Index)
#目前可以使用Pip安装
#类似yun, Apt-get, NPM

#命令格式
Pip install third-party library name

For example: Installing Selenium

C:\users\asus>pip Install Selenium

Requirement already satisfied:selenium in C:\users\asus\appdata\local\program
Python\python36\lib\site-packages
It says I've installed selenium.

Or install other: Pip install requests
-----------------------------------------------------------------------------------

Before installation, use the command: C:\users\asus>where pip to see how many pips, if there are multiple pips, you need to first add Python3.6.4 before the command

#卸载方式

PIP Uninstall requests

#指定版本安装
Pip Install somepackage==1.0.4 #specific version
Pip Install ' somepackage>=1.0.4 #minimum version

#更新安装
Pip Install Selenium-u

Python Basics 10 (module and package libraries installation use)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.