|
训练环境搭建 用vscode远程连接WSL。 安装Miniforge工具如果系统中同时有多个版本的Python环境,建议使用Miniforge管理Python环境。 1. 检查是否安装Miniforge和版本信息,若已安装则可省略此小节步骤。 | conda -V # 提示 conda: command not found 则表示未安装miniforge conda # 提示 例如版本 conda 23.9.0 |
2. 下载Miniforge安装包 3. 运行安装脚本 下载完成后,通过以下命令启动安装流程: | chmod 777 Miniforge3-Linux-x86_64.sh bash Miniforge3-Linux-x86_64.sh |
4. 配置环境变量 安装完成后,执行以下命令初始化Conda环境: | source ~/miniforge3/etc/profile.d/conda.sh |
若需永久生效,可将该命令添加到~/.bashrc文件中: | echo 'source ~/miniforge3/etc/profile.d/conda.sh' >> ~/.bashrc source ~/.bashrc |
此步骤确保conda命令全局可用。 创建虚拟环境(1) 创建名为py38_env的Python 3.8环境 | conda create -n py38_env python=3.8 -y |
命令参数解析: py38_env #指定新环境的名称为py38_env,-n是--name的简写(可以修改为自定义的环境名) python=3.8 #明确指定环境中安装Python 3.8版本 -y #自动确认安装过程中的所有提示(如依赖安装确认),无需手动输入y 运行该命令如果遇到以下问题: | CondaToSNonInteractiveError: Terms of Service have not been accepted for the following channels. Please accept or remove them before proceeding: To accept a channel's Terms of Service, run the following and replace `CHANNEL` with the channel name/URL: ‣ conda tos accept --override-channels --channel CHANNEL To remove channels with rejected Terms of Service, run the following and replace `CHANNEL` with the channel name/URL: ‣ conda config --remove channels CHANNEL |
该问题是Anaconda使用中的协议接受问题,需要解决conda create命令因未接受服务条款导致的报错。以下是分步解决方案:
第一步:接受服务条款 第二步:验证是否生效 | conda config --show channels # 确认频道状态 |
第三步:重新创建环境 | conda create -n py38_env python=3.8 -y |
(2) 激活py38_env环境 (3) 验证python安装 在虚拟环境中安装所需软件包进入我们创建的虚拟环境,安装所需依赖,将requirements.txt文件放入项目根目录下。 运行如下命令安装所有依赖: | pip install -r requirements.txt #下载时用国内镜像源加速下载 |
requirements.txt文件如下: | certifi==2025.8.3 charset-normalizer==3.4.3 coloredlogs==15.0.1 contourpy==1.1.1 cycler==0.12.1 filelock==3.16.1 flatbuffers==25.2.10 fonttools==4.57.0 fsspec==2025.3.0 humanfriendly==10.0 idna==3.10 importlib_resources==6.4.5 Jinja2==3.1.6 kiwisolver==1.4.7 markdown-it-py==3.0.0 MarkupSafe==2.1.5 matplotlib==3.7.5 mdurl==0.1.2 mpmath==1.3.0 networkx==3.1 numpy==1.24.4 nvidia-cublas-cu12==12.1.3.1 nvidia-cuda-cupti-cu12==12.1.105 nvidia-cuda-nvrtc-cu12==12.1.105 nvidia-cuda-runtime-cu12==12.1.105 nvidia-cudnn-cu12==9.1.0.70 nvidia-cufft-cu12==11.0.2.54 nvidia-curand-cu12==10.3.2.106 nvidia-cusolver-cu12==11.4.5.107 nvidia-cusparse-cu12==12.1.0.106 nvidia-nccl-cu12==2.20.5 nvidia-nvjitlink-cu12==12.9.86 nvidia-nvtx-cu12==12.1.105 onnx==1.17.0 onnxruntime==1.19.2 onnxsim==0.4.36 opencv-python==4.12.0.88 packaging==25.0 pandas==2.0.3 pillow==10.4.0 polars==1.8.2 protobuf==5.29.5 psutil==7.0.0 Pygments==2.19.2 pyparsing==3.1.4 python-dateutil==2.9.0.post0 pytz==2025.2 PyYAML==6.0.2 requests==2.32.4 rich==14.1.0 scipy==1.10.1 six==1.17.0 sympy==1.13.3 torch==2.4.1 torchvision==0.19.1 tqdm==4.67.1 triton==3.0.0 typing_extensions==4.13.2 tzdata==2025.2 ultralytics==8.3.201 ultralytics-thop==2.0.17 urllib3==2.2.3 zipp==3.20.2 |
|