In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to automatically install third-party libraries in Python3". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to automatically install third-party libraries in Python3".
Catalogue
1. Introduction
2. Manual installation of pip
2.1 online installation
2.1.1 default installation
2.1.2 specified version installation
2.2 offline installation
2.3 set domestic sources
2.4 Uninstall and upgrade
2.4.1 Uninstall
2.4.2 upgrade
3. Automatic installation of pip.main
3.1 pip main installation
3.2 os installation
1. Introduction
Python automatically installs third-party libraries, completely liberating your hands!
2. Manual installation of pip
When it comes to installing third-party libraries in Python, our first reaction is that it must be installed in pip mode, no problem, necessary.
But think about it, if you change computers (Tuhao has changed computers, I have changed friends), and there are so many third-party libraries in Python, do you have to hit pip install?? again and again?
However, according to the process, we will first introduce the manual installation of pip, and then introduce today's corner: automatic installation of third-party libraries
2.1 online installation 2.1.1 default installation
It's a clich é, a direct order:
Pip install third-party library name 2.1.2 specify version installation
Specify the version installation command for the third-party library:
Pip install third-party library name = = version number
For example
Pip install selenium==3.3
Several ways to specify the version number:
If ① is not specified, the latest
② = = specify a specific version number
③ = specify the minimum version number
five
< 不高于某版本号 ⑥>No less than a certain version number
Be careful
Here's a hint. If you don't specify a specific version number, you need to use quotation marks (''), as follows:
Pip install selenium==3.32.2 offline installation
Many python libraries will time out online installation, or there is no network, at this time, you will think of offline installation.
After all, it's not right to fish at work.
It is also wrong to use the company network to download the installation package.
Here are two very comprehensive third-party library addresses. You are welcome, just take them away:
Health website: https://www.lfd.uci.edu/~gohlke/pythonlibs/
Pypi: https://pypi.org/
Little loser: brother Fish, offline installation, how many steps are there in total?
Xiaoyu: there are three steps in total. Please count with me:
Step 1: log in to the Python third-party library website
Step 2: download the files of the third library to the local
Step 3: install locally
Command
Pip install C:\ Project\ pyRXP-2.2.0-cp35-cp35m-win_amd64.whl2.3 set domestic source
Little loser: brother Fish, is there a way to install quickly without having to download it to the local place?
Fish: it's a must. Get in the car and follow the orders.
If you do not want to download to the local, but also want to directly install pip, then consider the domestic source image.
Command
Pip install plotly-I https://pypi.tuna.tsinghua.edu.cn/simple
The domestic source address is as follows:
Ali Cloud Image: http://mirrors.aliyun.com/pypi/simple/
Image of Tsinghua University: https://pypi.tuna.tsinghua.edu.cn/simple/
Douban image: http://pypi.doubanio.com/simple/
Mirror image of China University of Science and Technology: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/
Little loser: brother Fish, this is a good method, but I don't want to enter the address every time. Can I find a way to do it once and for all
Fish: … You are very demanding, but there can be some ways.
Just under your current project, create a pip.ini file and call the contents of the file directly to OK:
2.4 Uninstall and upgrade 2.4.1 Uninstall
If there is installation, there will be uninstallation.
It's also very simple, a command.
Pip uninstall third-party library name 2.4.2 upgrade
Before upgrading, we need to check it as follows:
1. View commands
① to view installed libraries
Pip list
② views the specified library
Pip show Library name
2. Upgrade command
① to view upgradeable libraries
Pip list-o
② upgrade command
Pip install-- upgrade library name 3, pip.main automatic installation 3.1 pip main installation
She came out shyly after thousands of calls, holding the pipa without covering her face!
The front has done so much groundwork, the protagonist appears, can applaud, do not stop the kind!
We've all been through it, and then other people's code (refusing to be the scapegoat) moved on, but there are some libraries that we didn't install.
At this time, it is very painful, keep reminding that there is no library, keep installing
It's hard to think about it.
Little loser: so is there a way to do it in one step?
Fish: yes, get in the car and put the code.
Code presentation
#-*-coding:utf-8-*-# @ Time: 2021-08-0permission @ Author: carl_DJ "" if the referenced library is not installed, it is automatically installed "" # in order to clarify the exception information We append the assertion try: import requests import pandas as pd from bs4 import BeautifulSoup import jieba import jieba.analyse import matplotlib.pyplot as plt from wordcloud import WordCloud,STOPWORDS import numpy as np from PIL import Image# installs dependent libraries using the pip.main () method (examples of several commonly used libraries) except ImportError: import pip pip.main (["install", "--user", "requests", "beautifulsoup4", "matplotlib", "wordcloud", "pandas") "pillow"]) import requests import pandas as pd from bs4 import BeautifulSoup import jieba import jieba.analyse import matplotlib.pyplot as plt from wordcloud import WordCloud,STOPWORDS import numpy as np from PIL import Image
To execute this code, all that is left is to liao (mei).
Because the small fish have been installed, so it will not be carried out.
3.2 os installation
Little loser: seeing this, I think I'm awesome.
Xiaoyu: where is it? I use a single line of code to install it automatically.
Little loser: I don't know.
Code presentation
#-*-coding:utf-8-*-# @ Time: 2021-08-0 libraries @ Author: libraries to be installed by carl_DJimport os# libs = ["requests", "beautifulsoup4", "matplotlib", "wordcloud", "pandas", "pillow"] # cycle through installation for lib in libs: os.system ("pip install" + lib) Thank you for reading, this is the content of "how to automatically install third-party libraries in Python3" After the study of this article, I believe you have a deeper understanding of how to automatically install third-party libraries in Python3, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.