Pytorch 、 torchtext和Python之间有严格的对应关系:?
在命令窗中安装torchtext
pip install torchtext
注意这种安装方式,在pytorch版本与python版本不兼容时动会自动更新并安装pytorch+cpu版本,安装的新版本pytorch可能会不兼容。慎用。?
如果不兼容会产生以下报错:
C:\Users\刘鸿逸>pip install torchtext
Collecting torchtext
Using cached torchtext-0.16.2-cp310-cp310-win_amd64.whl.metadata (7.5 kB)
Requirement already satisfied: tqdm in d:\python\lib\site-packages (from torchtext) (4.66.1)
Requirement already satisfied: requests in d:\python\lib\site-packages (from torchtext) (2.28.1)
Collecting torch==2.1.2 (from torchtext)
Using cached torch-2.1.2-cp310-cp310-win_amd64.whl.metadata (26 kB)
Requirement already satisfied: numpy in d:\python\lib\site-packages (from torchtext) (1.23.0)
Collecting torchdata==0.7.1 (from torchtext)
Using cached torchdata-0.7.1-cp310-cp310-win_amd64.whl.metadata (13 kB)
Requirement already satisfied: filelock in d:\python\lib\site-packages (from torch==2.1.2->torchtext) (3.12.0)
Requirement already satisfied: typing-extensions in d:\python\lib\site-packages (from torch==2.1.2->torchtext) (4.5.0)
Requirement already satisfied: sympy in d:\python\lib\site-packages (from torch==2.1.2->torchtext) (1.12)
Requirement already satisfied: networkx in d:\python\lib\site-packages (from torch==2.1.2->torchtext) (2.8.8)
Requirement already satisfied: jinja2 in d:\python\lib\site-packages (from torch==2.1.2->torchtext) (3.1.2)
Collecting fsspec (from torch==2.1.2->torchtext)
Using cached fsspec-2023.12.2-py3-none-any.whl.metadata (6.8 kB)
Requirement already satisfied: urllib3>=1.25 in d:\python\lib\site-packages (from torchdata==0.7.1->torchtext) (1.26.12)
Requirement already satisfied: charset-normalizer<3,>=2 in d:\python\lib\site-packages (from requests->torchtext) (2.1.1)
Requirement already satisfied: idna<4,>=2.5 in d:\python\lib\site-packages (from requests->torchtext) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in d:\python\lib\site-packages (from requests->torchtext) (2022.9.24)
Requirement already satisfied: colorama in d:\python\lib\site-packages (from tqdm->torchtext) (0.4.6)
Requirement already satisfied: MarkupSafe>=2.0 in d:\python\lib\site-packages (from jinja2->torch==2.1.2->torchtext) (2.1.1)
Requirement already satisfied: mpmath>=0.19 in d:\python\lib\site-packages (from sympy->torch==2.1.2->torchtext) (1.3.0)
Using cached torchtext-0.16.2-cp310-cp310-win_amd64.whl (1.9 MB)
Downloading torch-2.1.2-cp310-cp310-win_amd64.whl (192.3 MB)
---------------------------------------- 192.3/192.3 MB 920.3 kB/s eta 0:00:00
Downloading torchdata-0.7.1-cp310-cp310-win_amd64.whl (1.3 MB)
---------------------------------------- 1.3/1.3 MB 716.2 kB/s eta 0:00:00
Downloading fsspec-2023.12.2-py3-none-any.whl (168 kB)
---------------------------------------- 169.0/169.0 kB 635.0 kB/s eta 0:00:00
Installing collected packages: fsspec, torch, torchdata, torchtext
Attempting uninstall: torch
Found existing installation: torch 2.0.1
Uninstalling torch-2.0.1:
Successfully uninstalled torch-2.0.1
WARNING: Failed to remove contents in a temporary directory 'D:\Python\Lib\site-packages\~orch'.
You can safely remove it manually.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.15.2 requires torch==2.0.1, but you have torch 2.1.2 which is incompatible.
Successfully installed fsspec-2023.12.2 torch-2.1.2 torchdata-0.7.1 torchtext-0.16.2
?ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.15.2 requires torch==2.0.1, but you have torch 2.1.2 which is incompatible.
Successfully installed fsspec-2023.12.2 torch-2.1.2 torchdata-0.7.1 torchtext-0.16.2
已经成功安装了torchtext
和其依赖的torch
2.1.2版本,但这个版本的torch
与系统中已安装的torchvision
0.15.2版本不兼容,因为torchvision
0.15.2要求torch
版本为2.0.1。
?使用以下命令解决版本问题:
pip install torch==2.0.1
?