Pycharm使用Anaconda环境
打开Anaconda Prompt,创建Anaconda环境
输入命令:conda create -n newenv python=3.8(newenv可替换为自定义环境名称,3.8可替换为自己想要的Python版本)
系统会配置所需要的包
输入“y”然后回车,开始安装
安装后,可使用以下命令激活/关闭环境
安装所需要的包
以Opencv、Pytorch为例,推荐使用conda命令安装,勿与pip命令混用。
推荐使用清华镜像源,下载速度更快。
输入以下命令添加镜像源:
conda config –-add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config –-add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config –-add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
conda config –-add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config –-add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config –-set show_channel_urls yes
另外可以在Windows系统的当前用户目录下,创建或修改.condarc文件,文件内容如下:
channels:
-https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
-https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
-http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
-http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
-http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
-defaults
show_channel_urls: true
输入以下命令安装opencv:
conda install opencv
(相关的包包括Numpy等,为了防止版本混乱,不建议单独安装Numpy)
到Pytorch官网查询合适版本的安装命令(Pytorch官网:https://pytorch.org)
这里需要去掉命令最后的==-c pytorch==,这样才会用清华源进行下载
安装完成后可使用Python检测是否可以正确导入模块
Pycharm使用Anaconda环境
File->New Project
选择Conda Environment
找到Anaconda所在文件路径中envs文件夹里想要环境的python.exe文件
然后完成项目的创建
已有的项目可以在界面右下角直接切换为conda环境