方法一:使用系统Python解释器
-
打开PyCharm
-
进入
File
→Settings
→Project
→Python Interpreter
-
点击右侧的
Add Interpreter,
选择Add Local Interpreter
-
选择
System Interpreter
-
在解释器路径中,选择你安装PyTorch时使用的Python解释器
-
通常路径如:
C:\Users\用户名\AppData\Local\Programs\Python\PythonXX\python.exe
-
或Anaconda路径:
C:\Users\用户名\anaconda3\python.exe
-
方法二:使用现有虚拟环境
如果你在虚拟环境中安装了PyTorch:
-
在
Add Python Interpreter
窗口中选择Existing environment
-
找到虚拟环境的Python解释器,通常在:
-
C:\Users\用户名\venv\Scripts\python.exe
(venv) -
C:\Users\用户名\anaconda3\envs\环境名\python.exe
(conda)
-