关于python第三方库问题整理
文章目录
一、查看安装的第三方库
通过命令提示符查看
- 在电脑上打开命令提示符(可以在桌面通过输入
win
+r
,进入搜索再输入cmd
进入命令提示符)
输入pip list
就会显示安装的第三方库和版本号
C:\Users\Lenovo>pip list
Package Version
------------------------- ---------
altgraph 0.17
certifi 2020.6.20
chardet 3.0.4
future 0.18.2
idna 2.10
pefile 2019.4.18
pip 19.0.3
pyinstaller 4.0
pyinstaller-hooks-contrib 2020.10
pywin32-ctypes 0.2.0
requests 2.24.0
setuptools 40.8.0
urllib3 1.25.10
通过安装位置查找
-
进去python的安装路径中查看。在你之前选着安装python路径下的目录(D:\software\python\Lib\site-packages)
-
这样可以看到安装的第三方库的文件夹
二、安装第三方库(例如装jieba)
可以在命令提示符下安装,或者在集成开发环境中安装(如:pycharm)
- 在命令提示符下操作
- 输入
pip install
+第三方库名称
- 如:pip install jieba
C:\Users\Lenovo>pip install jieba
Collecting jieba
Downloading https://files.pythonhosted.org/packages/c6/cb/18eeb235f833b726522d7ebed54f2278ce28ba9438e3135ab0278d9792a2/jieba-0.42.1.tar.gz (19.2MB)
52% |█████████████████ | 10.0MB 31kB/s eta 0:04:48Exception:
Traceback (most recent call last):
File "d:\software\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 360, in _error_catcher
yield
File "d:\software\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 442, in read
data = self._fp.read(amt)
File "d:\software\python\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "d:\software\python\lib\http\client.py", line 457, in read
n = self.readinto(b)
File "d:\software\python\lib\http\client.py", line 501, in readinto
n = self.fp.readinto(b)
File "d:\software\python\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "d:\software\python\lib\ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "d:\software\python\lib\ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\software\python\lib\site-packages\pip\_internal\cli\base_command.py", line 179, in main
status = self.run(options, args)
File "d:\software\python\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
resolver.resolve(requirement_set)
File "d:\software\python\lib\site-packages\pip\_internal\resolve.py", line 131, in resolve
self._resolve_one(requirement_set, req)
File "d:\software\python\lib\site-packages\pip\_internal\resolve.py", line 294, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "d:\software\python\lib\site-packages\pip\_internal\resolve.py", line 242, in _get_abstract_dist_for
self.require_hashes
File "d:\software\python\lib\site-packages\pip\_internal\operations\prepare.py", line 334, in prepare_linked_requirement
progress_bar=self.progress_bar
File "d:\software\python\lib\site-packages\pip\_internal\download.py", line 878, in unpack_url
progress_bar=progress_bar
File "d:\software\python\lib\site-packages\pip\_internal\download.py", line 702, in unpack_http_url
progress_bar)
File "d:\software\python\lib\site-packages\pip\_internal\download.py", line 946, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "d:\software\python\lib\site-packages\pip\_internal\download.py", line 639, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "d:\software\python\lib\site-packages\pip\_internal\utils\hashes.py", line 62, in check_against_chunks
for chunk in chunks:
File "d:\software\python\lib\site-packages\pip\_internal\download.py", line 607, in written_chunks
for chunk in chunks:
File "d:\software\python\lib\site-packages\pip\_internal\utils\ui.py", line 159, in iter
for x in it:
File "d:\software\python\lib\site-packages\pip\_internal\download.py", line 596, in resp_read
decode_content=False):
File "d:\software\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "d:\software\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "d:\software\python\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "d:\software\python\lib\site-packages\pip\_vendor\urllib3\response.py", line 365, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
You are using pip version 19.0.3, however version 20.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
然而很意外,没装上,原因是时间超时(ReadTimeoutError),外网太慢,下载速度跟龟速似的
但是通过国内的镜像就很快
如果安装第三方库由于时间超时,下载速度慢导致安装失败,可以使用国内的镜像进行安装
这个是pypi镜像使用的方式 使用
这样通过在命令行输入pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jieba
运行结果:
C:\Users\Lenovo>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jieba
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting jieba
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c6/cb/18eeb235f833b726522d7ebed54f2278ce28ba9438e3135ab0278d9792a2/jieba-0.42.1.tar.gz (19.2MB)
100% |████████████████████████████████| 19.2MB 1.8MB/s
Installing collected packages: jieba
Running setup.py install for jieba ... done
Successfully installed jieba-0.42.1
You are using pip version 19.0.3, however version 20.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
成功安装jieba库
再查找一下输入pip list
C:\Users\Lenovo>pip list
Package Version
------------------------- ---------
altgraph 0.17
certifi 2020.6.20
chardet 3.0.4
future 0.18.2
idna 2.10
jieba 0.42.1
pefile 2019.4.18
pip 19.0.3
pyinstaller 4.0
pyinstaller-hooks-contrib 2020.10
pywin32-ctypes 0.2.0
requests 2.24.0
setuptools 40.8.0
urllib3 1.25.10
发现就有jieba
了
三、删除第三方库
通过pip命令删除
- 打开命令提示符,输入
pip uninstall 库名
,
例如卸载pyinstaller
,输入pip uninstall pyinstaller
然后会出现是否确认删除,输入y
,最后会显示Successfully uninstaller pyinstaller-4.0
C:\Users\Lenovo>pip uninstall pyinstaller
Uninstalling pyinstaller-4.0:
Would remove:
d:\software\python\lib\site-packages\pyinstaller-4.0.dist-info\*
d:\software\python\lib\site-packages\pyinstaller\*
d:\software\python\scripts\pyi-archive_viewer.exe
d:\software\python\scripts\pyi-bindepend.exe
d:\software\python\scripts\pyi-grab_version.exe
d:\software\python\scripts\pyi-makespec.exe
d:\software\python\scripts\pyi-set_version.exe
d:\software\python\scripts\pyinstaller.exe
Proceed (y/n)?y
Successfully uninstaller pyinstaller-4.0
- 确认是否已经删除可以通过输入
pip list
查看还有没有pyinstaller
手动删除
- 如果不能使用pip命令删除,可以在安装路径上删除
如D:\software\python\Lib\site-packages在该路径下查找要删除的库
一般在python安装路径下\Lib\site-packages文件夹内