安装miniconda实现python包管理,并通过vscode进行编写python代码
miniconda简单介绍
Miniconda 是 Anaconda 公司的一个轻量级 Python 发行版本,它包含了最基本的包管理器 conda
和 Python 环境,只带最核心的组件,没有额外的大量科学计算库。
miniconda下载与安装
下载
清华大学镜像下载:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
安装
这一步把添加环境变量勾上就ok
配置
换源
使用记事本打开Conda的配置文件.condarc
用下面代码替换掉文件内容
channels:- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudmsys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudbioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudmenpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudpytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudsimpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
[可选]改变新环境的默认添加位置
使用记事本打开Conda的配置文件.condarc
添加上下面代码,其中地址换成自己想换的位置
envs_dirs:- D:\01_Application\miniconda3\envs
检验:打开Anaconda Prompt,输入conda info,其中就有源和env存储位置等各种信息
注:
若修改了存储位置,任没有效果,可能是目标文件夹权限问题,点击目标文件夹属性,把特殊权限之外的权限全开了即可
miniconda简单操作
查看版本
conda -V
查看信息
conda info
查看环境列表
conda env list
创建环境
conda create -n your_env_name python=3.11
激活环境
conda activate your_env_name
base变为你给环境起的名字
之后在这里下载包就会存放在本环境位置
关闭环境
conda deactivate your_env_name
vscode操作
安装python插件
选择python环境
1.ctrl+shift+p,点击选择python解释器
2.选择你要使用的环境名字
编写并运行代码
演示
import numpy as np
import matplotlib.pyplot as plt# 参数 t
t = np.linspace(0, 2 * np.pi, 1000)# 心形曲线公式
x = 16 * np.sin(t) ** 3
y = 13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t)# 绘图
plt.figure(figsize=(6, 6))
plt.plot(x, y, color='red', linewidth=2)
plt.fill(x, y, color='red', alpha=0.6) # 填充颜色
plt.axis('equal') # 保持比例
plt.axis('off') # 去掉坐标轴# 展示图形
plt.show()