anconda、miniconda、miniforge、jupyter notebook的安装

anconda下载及安装要点

anconda下载地址:https://www.anaconda.com/products/distribution
官网下载需要注册,下面给出了一个anconda3的百度云下载链接:
https://pan.baidu.com/s/18Rx2paRtau_qS1hA8IfU0w 提取码:dah0

安装

双击下载好的.exe文件,点击 Next 即可。

点击Next

点击 I Agree (我同意),不同意,当然就没办法继续安装啦。

Install for: Just me还是All Users,假如你的电脑有好几个 Users ,才需要考虑这个问题.其实我们电脑一般就一个 User,就我们一个人使用,如果你的电脑有多个用户,选择All Users,我这里直接 All User,继续点击 Next 。

Destination Folder 是“目标文件夹”的意思,可以选择安装到什么地方。默认是安装到 C:\ProgramData\Anaconda3文件夹下。你也可以选择 Browse… ,选择想要安装的文件夹。我这里 C 盘空间充裕,所以我直接就装到默认的地方。

这里提一下,Anaconda 很强大,占用空间也不小啊,6GB(包含后续安装的2个python版本)。不过,为了学习,这点硬盘空间算什么呢。

继续点击 Next> 。

这里来到 Advanced Options 了,所谓的“高级选项”。如果你英文好,有一定背景知识的话,肯定明白这界面上的意思。两个默认就好,第一个是加入环境变量,第二个是默认使用 Python 3.X,点击“Install”,终于开始安装额。

安装时间根据你的电脑配置而异,电脑配置高,硬盘是固态硬盘,速度就更快。

过程还是很漫长的,耐心等待。

经过漫长的等待,终于安装完成 Installation Complete (安装完成)了,点击最后一个 Next>。

点击Install Microsoft VSCode(可跳过)

点击 Finish,那两个 √ 可以取消。

配置环境变量

如果是windows的话需要去 控制面板\系统和安全\系统\高级系统设置\环境变量\用户变量\PATH 中添加 anaconda的安装目录的Scripts文件夹, 比如我的路径是C:\ProgramData\Anaconda3\Scripts, 看个人安装路径不同需要自己调整.

之后就可以打开命令行(最好用管理员模式打开) 输入 conda --version

如果输出conda x.x.x之类的就说明环境变量设置成功了.

为了避免可能发生的错误, 我们在命令行输入 conda upgrade --all 先把所有工具包进行升级。

管理虚拟环境

activate

activate 能将我们引入anaconda设定的虚拟环境中, 如果你后面什么参数都不加那么会进入anaconda自带的base环境。

如果系统中装有python版本,在CMD中输入python会显示系统安装的python版本(非anconda中)

创建自己的虚拟环境

创建一个名称为python310的虚拟环境并指定python版本为3.10(这里conda会自动找3.10中最新的版本下载)

conda create -n python310 python=3.10

或者conda create --name python310 python=3.10

默认的安装位置会在:C:\ProgramData\Anaconda3\envs
如果安装位置在:C:\Users\xxx.conda\envs\ 中,后续可能会出现在pycharm中无法选择编译器的问题,具体解决办法为 找到 C:\Users\具体用户账号.condarc ,找不到的话,可直接在Users目录下搜索
找到后,记事本打开并添加

envs_dirs:
  - C://Anaconda//envs #新的环境保存位置

保存,再次试一下创建环境
失败的话,请参考: https://blog.csdn.net/QH2107/article/details/126246310

切换环境

activate python310

如果忘记了名称我们可以先用

conda env list

卸载环境

conda remove --name test --all

安装对应环境下的第三方包

输入

conda install requests

或者

pip install requests

来安装requests包.

如果安装失败或速度慢的话,可使用清华源进行安装
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx
# 这里注意,xxx是需要下载的包的名字,例如:
# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch

此处可参考: https://blog.csdn.net/yyj3900636/article/details/122744249

查看环境包信息

要查看当前环境中所有安装了的包可以用

conda list
在这里插入图片描述
activate // 切换到base环境

activate learn // 切换到learn环境

conda create -n learn python=3 // 创建一个名为learn的环境并指定python版本为3(的最新版本)

conda env list // 列出conda管理的所有环境

conda list // 列出当前环境的所有包

conda install requests 安装requests包

conda remove requests 卸载requets包

conda remove -n learn --all // 删除learn环境及下属所有包

conda update requests 更新requests包

conda env export > environment.yaml // 导出当前环境的包信息

conda env create -f environment.yaml // 用配置文件创建新的虚拟环境

miniconda

下载地址1:https://docs.conda.io/en/latest/miniconda.html
下载地址2:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
anconda的下载地址2:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

miniforge

下载地址:https://github.com/conda-forge/miniforge

pip 安装第三方库

pip list:查看当前Python环境安装了哪些库。
pip install 库名:安装新库,注意三个词之间要用空格隔开。
pip install 库名1 库名2 库名3:同时安装多个库,多个库名之间用空格隔开。
pip install 库名-U:将库的版本升级到最新版。
pip uninstall 库名:卸载库。
此外,由于pip命令中存储库文件的服务器在境外,有时候会比较慢,可以在命令后增加-i参数,如:
pip install 库名 -i https://pypi.tuna.tsinghua.edu.cn/simple
-i后面是指定的镜像源,以上使用了清华大学的镜像源,由于其服务器在国内,下载速度非常快。除了清华大学的源,还可以使用豆瓣(https://pypi.douban.com/simple)、阿里云(http://mirrors.aliyun.com/pypi/simple)等提供的源。

一次性安装所有常用包,
pip install pandas xlrd openpyxl xlsxwriter requests lxml html5lib BeautifulSoup4 matplotlib seaborn plotly bokeh scipy statsmodels -i https://pypi.tuna.tsinghua.edu.cn/simple

  • Excel处理相关包:xlrd、openpyxl、XlsxWriter
  • 解析网页包:Requests、lxml、html5lib、Beautiful Soup 4
  • 可视化包:Matplotlib、seaborn、Plotly、Bokeh 计算包:SciPy、statsmodels

安装Jupyter Notebook

安装Jupyter Notebook,使用清华大学下载源加快下载速度
pip install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple
安装 Jupyter Lab 的命令如下
pip install jupyterlab

使用Jupyter Notebook: jupyter notebook
使用jupyter lab: jupyter lab

常用快捷键

  • Tab:代码提示(输入部分代码后按Tab键)。
  • Shift+Enter:执行本行并定位到新增的行。
  • Shift+Tab(1~3次):查看函数方法说明(光标在函数上按住
  • Shift再按Tab键一到三次)。
  • D D:双击D键删除本行。
  • A / B:向上/向下增加一行。
  • M / R:Markdown / 代码模式。

常见错误

错误1

ProxyError: Conda cannot proceed due to an error in your proxy configuration.
Check for typos and other configuration errors in any ‘.netrc’ file in your home directory,
any environment variables ending in ‘_PROXY’, and any other system-wide proxy
configuration settings.
处理办法:关闭网络代理

更改conda命令安装的python位置

修改.condarc文件

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
envs_dirs:
  - D:\Users\zh\anaconda3\envs

更改jupyter notebook的python版本

激活更换的python版本:
pip install ipykernel
python -m ipykernel install --name py38

找到D:\Users\zh\anaconda3\share\jupyter\kernels\python3中的kernel.json文件
{
“argv”: [
“D:/Users/zh/anaconda3\python.exe”,
“-m”,
“ipykernel_launcher”,
“-f”,
“{connection_file}”
],
“display_name”: “Python 3 (ipykernel)”,
“language”: “python”,
“metadata”: {
“debugger”: true
}
}
修改为
{
“argv”: [
“D:\Users\zh\anaconda3\envs\py38\python.exe”,
“-m”,
“ipykernel_launcher”,
“-f”,
“{connection_file}”
],
“display_name”: “Python 3 (ipykernel)”,
“language”: “python”,
“metadata”: {
“debugger”: true
}
}

在jupyter notebook中切换python版本
在这里插入图片描述

查看当前jupyter notebook的python版本,
方式1
在jupyter notebook中输入

import sys

print(sys.version)
print(sys.executable)

方式2
如果用户有 jupyter notebook,可以运行 jupyternotebook,在 jupyter notebook 的 help选项中的about ·子选项,可以查看当前 jupyter notebook 所使用的python 环境。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值