0. 背景
- 在使用 pip install 命令安装第三方包的时候,有时会遇到安装失败的问题;
- 在这些问题中,有一种问题很让人头大,那就是安装包本身就有问题;
-- 比如下面的案例中,安装包中的代码就因为编码格式问题,导致安装失败;
- 在这中情况下,我们往往就需要手动下载安装包,然后对安装包进行编辑,然后重新打包安装;
1. 环境
- windows 10;
- aiooss-0.1.2.;
2. 问题
- 使用 pip 安装 aiooss 包时出现如下报错:
Collecting aiooss
Using cached aiooss-0.1.2.tar.gz (16 kB)
ERROR: Command errored out with exit status 1:
command: 'c:\users\administrator\appdata\local\programs\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-sdyzxf6h\\aiooss\\setup.py'"'"'; __file__='"'"'C:\\Users\\Administrator\\AppData\\Local\\Temp\\pip-install-sdyzxf6h\\aiooss\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Administrator\AppData\Local\Temp\pip-pip-egg-info-o_o8y9ax'
cwd: C:\Users\Administrator\AppData\Local\Temp\pip-install-sdyzxf6h\aiooss\
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Administrator\AppData\Local\Temp\pip-install-sdyzxf6h\aiooss\setup.py", line 5, in <module>
readme = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 124: illegal multibyte sequence
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output
3. 原因
4. 解决
- 手动下载第三方文件包,将安装包解压缩(和前面第三步的工作一样,此处不赘述);
- 修改文件包,将上面图片箭头指向位置的代码,修改成下面的代码;
with open('README.rst', mode='r',encoding='UTF-8') as f:
readme = f.read()
- 找到 python 安装包 site-packages 路径,site-packages 就是 python 安装目录下的 Lib\site-packages;
where python # 查看 python 安装路径
- 下载 7z 压缩工具,下载地址:https://www.7-zip.org/,并安装;
- 使用 7Z 将前面修改好的文件包压缩成 tar 格式,并复制到 site-packages 目录中;
- pip 安装 tar 文件包。问题解决;
pip install aiooss-0.1.2.tar
Processing c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\aiooss-0.1.2.tar
Requirement already satisfied: aiohttp in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiooss==0.1.2) (3.6.2)
Requirement already satisfied: oss2 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiooss==0.1.2) (2.12.1)
Requirement already satisfied: multidict<5.0,>=4.5 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiohttp->aiooss==0.1.2) (4.7.6)
Requirement already satisfied: async-timeout<4.0,>=3.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiohttp->aiooss==0.1.2) (3.0.1)
Requirement already satisfied: yarl<2.0,>=1.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiohttp->aiooss==0.1.2) (1.5.1)
Requirement already satisfied: attrs>=17.3.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiohttp->aiooss==0.1.2) (19.3.0)
Requirement already satisfied: chardet<4.0,>=2.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aiohttp->aiooss==0.1.2) (3.0.4)
Requirement already satisfied: requests!=2.9.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from oss2->aiooss==0.1.2) (2.24.0)
Requirement already satisfied: crcmod>=1.7 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from oss2->aiooss==0.1.2) (1.7)
>Requirement already satisfied: pycryptodome>=3.4.7 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from oss2->aiooss==0.1.2) (3.9.8)
Requirement already satisfied: aliyun-python-sdk-kms>=2.4.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from oss2->aiooss==0.1.2) (2.11.0)
Requirement already satisfied: aliyun-python-sdk-core-v3>=2.5.5 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from oss2->aiooss==0.1.2) (2.13.11)
Requirement already satisfied: six in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from oss2->aiooss==0.1.2) (1.15.0)
Requirement already satisfied: idna>=2.0 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from yarl<2.0,>=1.0->aiohttp->aiooss==0.1.2) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from requests!=2.9.0->oss2->aiooss==0.1.2) (2020.6.20)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from requests!=2.9.0->oss2->aiooss==0.1.2) (1.25.10)
Requirement already satisfied: aliyun-python-sdk-core>=2.11.5 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aliyun-python-sdk-kms>=2.4.1->oss2->aiooss==0.1.2) (2.13.25)
Requirement already satisfied: jmespath<1.0.0,>=0.9.3 in c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages (from aliyun-python-sdk-core-v3>=2.5.5->oss2->aiooss==0.1.2) (0.10.0)
Using legacy 'setup.py install' for aiooss, since package 'wheel' is not installed.
Installing collected packages: aiooss
Running setup.py install for aiooss ... done
Successfully installed aiooss-0.1.2