pytorch 之 分开安装 torch 和 torchvision

27 篇文章 2 订阅

本人在工作时遇到了一个比较尴尬的问题,就是虚拟环境中已有固定版本的torch,但没有安装torchvision,因此很本能的安装:

pip install torchvision

如果直接这样安装的话,我们发现会连带安装新版本的torch,由于不是本人的虚拟环境,不想改变别人的torch版本。因此该方法行不通。

就在思考如何分开安装torch 和 torchvision,后来发现,只需下载较低版本的torchvision就可以解决我的问题。只要下载的版本大于0.3.x,就会下载更新torch。因此选择安装低版本的。

本人尝试了0.1.6版本(pip install torchvision == 0.1.6),发现版本过低,在使用torchvision.transforms时报错:

                                                module 'torchvision.transforms' has no attribute 'xxxx'。

这时我们要适当调高版本,因此本人下载了0.2.1pip install torchvision == 0.2.1),成功解决问题!

大家如果有什么问题可以继续调试版本,查阅torch和torchvision的版本对应关系,二者版本不匹配有时也会报错!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在PyCharm中安装torchtorchvision,你可以按照以下步骤进行操作: 1. 首先,你需要下载torchtorchvision安装包。你可以从PyTorch官方网站下载torch安装包,网址为。打开该链接后,找到适合你的操作系统和Python版本的安装包,并下载。 2. 安装torchtorchvision安装包。在PyCharm中,你可以使用以下两种方式来安装: - 在PyCharm的终端中使用pip命令来安装。在终端中输入以下命令: ``` pip install torch==x.x.x torchvision==x.x.x ``` 将"x.x.x"替换为你下载的安装包的具体版本号。 - 在PyCharm的Package Manager中安装。点击PyCharm的菜单栏中的"File",然后选择"Settings"。在弹出的窗口中,选择"Project: your_project_name",然后点击"Project Interpreter"。在右侧的窗口中,点击"+"按钮,然后搜索并选择torchtorchvision安装包,点击"Install Package"来安装。 3. 安装完成后,你可以在PyCharm中导入相应的库,并开始使用torchtorchvision。你可以使用以下代码验证安装是否成功: ```python import torch import torchvision # 验证torch是否安装成功 print(torch.__version__) # 验证torchvision是否安装成功 print(torchvision.__version__) ``` 请注意,根据你的操作系统和Python版本,安装过程可能会有所不同。确保你下载的安装包与你的操作系统和Python版本相匹配,以确保安装成功。 : https://download.pytorch.org/whl/torch_stable.html<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Pycharm 中Torch安装方法](https://blog.csdn.net/soderayer/article/details/128881688)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [pytorchtorchtorchvision 对应版本与链接及安装注意事项](https://blog.csdn.net/m0_56843848/article/details/129414600)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值