如何查看 torch 的安装位置 pip vs conda torch installation

how to see where exactly torch is installed pip vs conda torch installation

在我的机器上我不能“pip install torch”——我遇到臭名昭著的“单一源外部管理错误”——我无法修复它并使用了 anaconda 的“conda install torch”。

不过,检查版本很容易 - torch.__version__

但是如何查看它安装在哪里-火炬的主目录? 假设如果我通过 pip 和 conda 安装了两个手电筒 - 如何知道项目中使用了哪个?

import torch
print(torch__version__)

您可以获得脚本中导入的 torch 模块位置

import torch
print(torch.__file__)

pip show torch 在终端会给你所有需要的信息。

Name: torch
Version: 1.3.1
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: c:\programdata\anaconda3\lib\site-packages
Requires: numpy
Required-by: torchvision, torchtext, efficientunet-pytorch

如果您已经安装了 PyTorch 库,请打开 Google Colab,粘贴以下代码并点击 运行 按钮:

import torch
print(torch.__file__)

然后你会看到 PyTorch 的版本。

如果它不起作用,请转到 https://pytorch.org/get-started/locally/ 并按照有关如何安装 PyTorch 的说明进行操作,因为有时 Python PyTorch 有依赖问题。