ubunutu20.04 pycharm使用anaconda下环境(主要是pytorch)

新建pycharm项目和anaconda环境

打开pycharm,new project
在这里插入图片描述在这里插入图片描述new environment using conda
修改环境名 项目名,python版本选择3.9(我的电脑pyTorch在3.9上跑通了,其他版本暂时没试)

create

打开终端,进入刚创建的conda环境
在这里插入图片描述
在该环境安装pyTorch,即在终端输入

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

在这里插入图片描述
在pyCharm验证是否成功

import torch

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    print(torch.cuda.is_available())
    print(torch.__version__)

在这里插入图片描述
输出结果如下:
在这里插入图片描述
成功!

新建pycharm项目,使用现有anaconda环境

new project ,使用默认环境
在这里插入图片描述
File-settings ,打开设置
在这里插入图片描述
点击python Interpreter
点击右上角 add Interpreter
在这里插入图片描述
选择add local interpreter,点击conda environment,选择 using existing environment,选择已配置好的环境,点击ok
在这里插入图片描述
点击右下角apply
在这里插入图片描述
点击ok

在pyCharm验证是否成功

import torch

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    print(torch.cuda.is_available())
    print(torch.__version__)

在这里插入图片描述
输出结果如下:
在这里插入图片描述
成功!

新建pycharm项目,使用现有anaconda环境-方法2

在这里插入图片描述
new project
点击 previously configured interpreter
选择已有环境

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!非常欢迎你提出问题。我将为你提供安装Anaconda的步骤。 请按照以下步骤在Ubuntu 20.04上安装Anaconda: 1. 首先,下载Anaconda的最新版本。你可以在Anaconda官方网站上找到下载链接:https://www.anaconda.com/products/individual#Downloads 2. 打开终端,进入你下载的Anaconda安装包所在的目录。可以使用以下命令进入Downloads目录: ``` cd Downloads ``` 3. 使用下面的命令来为Anaconda安装包添加可执行权限: ``` chmod +x Anaconda3-<版本号>-Linux-x86_64.sh ``` 请确保将"<版本号>"替换为你下载的实际版本号。 4. 运行安装脚本进行安装: ``` ./Anaconda3-<版本号>-Linux-x86_64.sh ``` 同样,请将"<版本号>"替换为你下载的实际版本号。 5. 安装过程中,你会看到一些许可条款。按下空格键逐页阅读并接受所有条款。 6. 接下来,将会提示你选择安装路径。默认情况下,Anaconda将被安装在家目录下的anaconda3文件夹中。如果你想选择不同的路径,请在此处进行修改。 7. 完成安装后,终端会提示你是否将Anaconda添加到系统的PATH环境变量中。输入"yes"并按下回车键。 8. 安装过程完成后,你可以关闭终端窗口。 恭喜!你已经成功在Ubuntu 20.04上安装了Anaconda。你可以在终端中输入"anaconda-navigator"命令来启动Anaconda Navigator图形界面,或者输入"conda"命令来使用Anaconda的命令行工具。 希望这对你有所帮助!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值