安装配置Anaconda,配置VSCode


记录一下笔者收集的一些资料,不喜勿喷。

Anaconda介绍

Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便地解决多版本python并存、切换以及各种第三方包安装问题。Anaconda利用工具/命令conda来进行package和environment的管理,并且已经包含了Python和相关的配套工具。

参考:https://blog.csdn.net/taoqick/article/details/56284364

下载Anaconda

清华大学anaconda镜像下载地址:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

选择一个合适的版本进行下载,笔者选择的是:

Anaconda3-2022.05-Windows-x86_64.exe

安装Anaconda

一路安装成功之后。打开Anaconda Powershell Prompt (anaconda3)。查看下Python版本(默认base环境):

(base) PS C:\Users\admin> python -V
Python 3.9.12

说明安装成功

换源

替换软件包的安装源,俗称“换源”。

执行conda config,参考:

https://blog.csdn.net/qq_41946216/article/details/129478882

https://zhuanlan.zhihu.com/p/459601766

会在当前系统用户的家目录下(比如admin用户就是C:\Users\admin),创建一个.condarc文件。

为了提升依赖包的安装速度,需要讲配置文件内容修改为:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
show_channel_urls: true

.condarc配置文件修改保存后,打开一个Anaconda Prompt,通过conda config --show-sources命令,可查看当前的配置:

(base) PS C:\Users\admin> conda config --show-sources
==> C:\Users\admin\.condarc <==
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
show_channel_urls: True

创建一个新环境

打开Anaconda Prompt,在控制台使用conda命令。

比如基于Python3.8.10,创建一个test环境:

conda create -n test python=3.8.10

切换到新建的test环境:

conda activate test

新环境下,用pip命令安装一个numpy包:

conda install numpy==1.21.6 -i https://pypi.tuna.tsinghua.edu.cn/simple

其中-i https://pypi.tuna.tsinghua.edu.cn/simple是要用国内清华大学的镜像源来安装。否则从国外下载可能会失败。

同理可以安装需要的其他软件包。

永久换源

永久设置pip命令从清华源安装软件包:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

执行后,会创建一个pip.ini文件,文件内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]
trusted-host = mirrors.aliyun.com

pip常用命令

pip install -r requirements.txt
# 从github安装
pip install git+https://github.com/mlech26l/keras-ncp.git

conda常用命令

conda info --envs 查看各个环境所在的位置
conda list:查看环境中的所有包
conda install XXX:安装 XXX 包
conda remove XXX:删除 XXX 包
conda env list:列出所有环境
conda create -n XXX:创建名为 XXX 的环境
conda create -n env_name jupyter notebook :创建虚拟环境
conda activate noti(或 source activate noti):启用/激活环境
conda env remove -n noti:删除指定环境
deactivate(或 source deactivate):退出环境
jupyter notebook :打开Jupyter Notebook
conda config --remove-key channels :换回默认源

VSCode环境配置

让VSCode使用conda创建的环境:

  • 打开VS Code,打开你的项目文件夹。
  • 按下快捷键Shift+Ctrl+P打开命令面板,输入“Python”,选择“Python: Select Interpreter”。
  • 在弹出的列表中选择你刚刚创建的Conda环境。VS Code会自动在项目文件夹下创建一个.conda文件夹来存放环境信息。

参考

CUDA 和 cuDNN

CUDA下载:
https://developer.nvidia.com/cuda-toolkit-archive
cuDNN下载:
https://developer.nvidia.com/rdp/cudnn-archive
https://docs.nvidia.com/deeplearning/cudnn/latest/
https://docs.nvidia.com/deeplearning/cudnn/installation/latest/windows.html

安装教程,参考:
https://blog.csdn.net/weixin_44779079/article/details/141528972
https://zhuanlan.zhihu.com/p/32400431090

Pytorch

https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/

Carla模拟环境学习视频

https://www.bilibili.com/video/BV17Q4y1K7Rq/

### 安装 Visual Studio Code 为了在 Ubuntu 系统上安装 Visual Studio Code (VS Code),可以采用官方推荐的方法来获取最新版本。通过命令行执行以下操作: #### 添加 Microsoft GPG 密钥 ```bash wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ ``` #### 配置软件仓库 对于稳定的发布版,添加如下列表文件: ```bash sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' ``` #### 更新包索引并安装 VS Code 更新本地包缓存,并安装 VS Code: ```bash sudo apt update sudo apt install code ``` 完成上述步骤后即可成功安装 Visual Studio Code。 ### 配置 Anaconda Python 环境于 VS Code 中 为了让 VS Code 使用 Anaconda 提供的 Python 解释器,在终端内输入 `which python` 或者 `which python3` 来确认 Anaconda 是否已经被正确设置到系统的 PATH 变量中[^1]。 如果未发现 Anaconda 的路径,则需手动将其加入至 `.bashrc` 文件里(假设已安装 Anaconda 至默认位置): ```bash echo 'export PATH="/home/$USER/anaconda3/bin:$PATH"' >> ~/.bashrc source ~/.bashrc ``` 启动或重启 VS Code 后,打开任意 Python 文件,点击左下角显示当前解释器名称的地方选择所需使用的 Anaconda 版本解析器。也可以通过命令面板 (`Ctrl+Shift+P`) 输入 “Python Select Interpreter”,从中挑选合适的选项[^3]。 另外,建议安装 Python 扩展插件以便更好地支持开发工作流中的调试和其他特性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值