Pycharm+Pytorch安装
安装环境
操作系统 | windows 11 |
---|---|
Pycharm版本 | PyCharm Professional |
Python | 3.10.5 |
pytorch | 1.12.0 |
torchvision | 0.13.0 |
通过学校邮箱可以注册JetBrains账号,免费使用professional版本,没有学校邮箱的可以下载社区版
社区版官网链接:Pycharm Community
官网地址:Pycharm 官网
本教程是非破解版安装!!
1. Pycharm安装
这里以安装Pycharm专业版为例
- 下载安装包:PyCharm Professional|
- 双击打开安装包
- 更改安装目录
- 勾选选项-下一步
- 保持默认,点击安装
- 安装成功
2. Pycharm激活
社区版用户可以直接使用,不需要看下面的部分
对于使用专业版的用户,需要登陆对应的学校邮箱账号(edu.cn结尾)获取激活码,激活码获取教程见2*
- 打开Pycharm
- 接受并继续
- 激活许可证
- 登陆账号
- 选择邮箱登录
- 输入教育邮箱
- 返回软件可以看到如下界面,点击激活
- 激活成功
2* 教育激活码申请
- 打开官网->Education->For students and teachers
- 往下滑->Apply now
- 开始注册流程
- 教育邮箱会收到邮件,按照邮件提示操作
- 完成后用教育邮箱登陆,邮箱会接受验证码
- 选择Pycharm点击下载
- 选择合适版本下载
- 后续过程参考前文激活教程
3. conda创建虚拟环境
CONDA/CUDA 安装过程见链接
下面步骤需要提前安装CONDA和CUDA
- 打开Anaconda prompt创建test虚拟环境
- 命令行输入
conda create -n test python=3.8
(base) C:\Users\17741>conda create -n test python=3.8
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 23.5.2
latest version: 24.9.2
Please update conda by running
$ conda update -n base -c defaults conda
Or to minimize the number of packages updated during conda update use
conda install conda=24.9.2
## Package Plan ##
environment location: D:\anaconda\envs\test
added / updated specs:
- python=3.8
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2024.9.24 | haa95532_0 131 KB
libffi-3.4.4 | hd77b12b_1 122 KB
openssl-3.0.15 | h827c3e9_0 7.8 MB
pip-24.2 | py38haa95532_0 2.4 MB
python-3.8.20 | h8205438_0 19.4 MB
setuptools-75.1.0 | py38haa95532_0 1.6 MB
sqlite-3.45.3 | h2bbff1b_0 973 KB
vc-14.40 | h2eaa2aa_1 10 KB
vs2015_runtime-14.40.33807 | h98bb1dd_1 1.3 MB
wheel-0.44.0 | py38haa95532_0 137 KB
------------------------------------------------------------
Total: 33.8 MB
The following NEW packages will be INSTALLED:
ca-certificates pkgs/main/win-64::ca-certificates-2024.9.24-haa95532_0
libffi pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
openssl pkgs/main/win-64::openssl-3.0.15-h827c3e9_0
pip pkgs/main/win-64::pip-24.2-py38haa95532_0
python pkgs/main/win-64::python-3.8.20-h8205438_0
setuptools pkgs/main/win-64::setuptools-75.1.0-py38haa95532_0
sqlite pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
vc pkgs/main/win-64::vc-14.40-h2eaa2aa_1
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.40.33807-h98bb1dd_1
wheel pkgs/main/win-64::wheel-0.44.0-py38haa95532_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate test
#
# To deactivate an active environment, use
#
# $ conda deactivate
- 打开Pycharm软件,新建项目并选择test虚拟环境
这里随便创建一个项目,进去之后再设置python解释器
- 设置项目python解释器
加载环境成功
4. 安装torch+torchvision
- whl包准备:去镜像网站下载需要的torch和torchvision版本(选择带有
cuxxx
的版本) - 教程选择版本如下:
版本 | |
---|---|
torch | torch-1.12.0+cu113-cp38-cp38-win_amd64.whl |
torchvision | torchvision-0.13.0+cu113-cp38-cp38-win_amd64.whl |
- 使用pip安装
在使用pip前先使用镜像源升级pip版本
python -m pip install pip==20.2.4 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install pip install .\torch-1.12.0+cu113-cp38-cp38-win_amd64.whl
(test) PS D:\ENVIRONMENT_windows\cp38> pip install .\torch-1.12.0+cu113-cp38-cp38-win_amd64.whl
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Processing d:\environment_windows\cp38\torch-1.12.0+cu113-cp38-cp38-win_amd64.whl
Collecting typing-extensions
Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Installing collected packages: typing-extensions, torch
Successfully installed torch-1.12.0+cu113 typing-extensions-4.12.2
pip install .\torchvision-0.13.0+cu113-cp38-cp38-win_amd64.whl
(test) PS D:\ENVIRONMENT_windows\cp38> pip install .\torchvision-0.13.0+cu113-cp38-cp38-win_amd64.whl
- 测试安装是否成功
(test) PS D:\PycharmProject\test1> python
Python 3.8.20 (default, Oct 3 2024, 15:19:54) [MSC v.1929 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>
>>>
>>> print(torch.cuda.is_available())
True
显示为
True
则安装成功