AttributeError:模块“syft”没有属性“TorchHook”

2024-05-23 10:57:46 发布

您现在位置:Python中文网/ 问答频道 /正文

请向专家寻求帮助:当我在python中使用pysyft库时,我遇到了这个错误( AttributeError:模块“syft”没有属性“TorchHook”)

这是我的代码截图 [1] :https://i.stack.imgur.com/rPxWw.png

我的环境: Spyder(Python IDE) Ubuntu 20.04 Python3


Tags: 模块代码httpscom属性pngstack错误
2条回答

您正在使用的syft版本是v0.3.0+。它不包含syft.TorchHook,因为我相信我读到那里不需要它。 使用pip install syft==0.2.9来使用syft.TorchHook()。特别是如果你正在遵循Andrew Trask,Openmined提供的安全和私人课程

请注意,如果您确实在学习该课程,OpenMine团队已经引入了一个新的更新课程。有关更多详细信息,请参见https://courses.openmined.org/courses/foundations-of-private-computation。它基于syft的更新版本

我想添加一个附加问题:如果在使用PIP install syft==0.2.9时发现以下问题

Could not find a version that satisfies the requirement torch~=1.4.0 (from syft) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)

您可以参考以下方法来解决:

pip install syft -f https://download.pytorch.org/whl/torch_stable.html

原因:

  1. 并非所有PyTorch版本都可以在Python的包注册表PyPI上使用

  2. -f:添加自定义注册表

    -f, find-links <url>

    If a URL or path to an html file, then parse for links to archives such as sdist (.tar.gz) or wheel (.whl) files. If a local path or file:// URL that’s a directory, then look for archives in the directory listing. Links to VCS project URLs are not supported.

  3. 请参阅此link

相关问题 更多 >

    热门问题