云服务器内容精选

  • 重新启动镜像激活SFS盘中的虚拟环境 方法一,直接使用完整conda env路径。 # shell conda activate /home/ma-user/work/envs/user_conda/sfs-new-env 方法二,先添加虚拟环境到conda env,然后使用名称激活。 # shell conda config --append envs_dirs /home/ma-user/work/envs/user_conda/ conda activate sfs-new-env 方法三,直接使用完成虚拟环境中的python或者pip。 # shell /home/ma-user/work/envs/user_conda/sfs-new-env/bin/pip list /home/ma-user/work/envs/user_conda/sfs-new-env/bin/python -V
  • 保存并共享虚拟环境 将要迁移的虚拟环境打包。 # shell pip install conda-pack conda pack -n sfs-clone-env -o sfs-clone-env.tar.gz --ignore-editable-packages Collecting packages... Packing environment at '/home/ma-user/work/envs/user_conda/sfs-clone-env' to 'sfs-clone-env.tar.gz' [########################################] | 100% Completed | 3min 33.9s 解压到SFS目录。 # shell mkdir /home/ma-user/work/envs/user_conda/sfs-tar-env tar -zxvf sfs-clone-env.tar.gz -C /home/ma-user/work/envs/user_conda/sfs-tar-env 查看现有的conda虚拟环境。 # shell conda env list # conda environments: # base /home/ma-user/anaconda3 PyTorch-1.8 * /home/ma-user/anaconda3/envs/PyTorch-1.8 python-3.7.10 /home/ma-user/anaconda3/envs/python-3.7.10 sfs-clone-env /home/ma-user/work/envs/user_conda/sfs-clone-env sfs-new-env /home/ma-user/work/envs/user_conda/sfs-new-env sfs-tar-env /home/ma-user/work/envs/user_conda/sfs-tar-env test-env /home/ma-user/work/envs/user_conda/test-env
  • 克隆原有的虚拟环境到SFS盘 # shell conda create --prefix /home/ma-user/work/envs/user_conda/sfs-clone-env --clone PyTorch-1.8 -y Source: /home/ma-user/anaconda3/envs/PyTorch-1.8 Destination: /home/ma-user/work/envs/user_conda/sfs-clone-env Packages: 20 Files: 39687 Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate /home/ma-user/work/envs/user_conda/sfs-clone-env # # To deactivate an active environment, use # # $ conda deactivate 查看新创建的clone虚拟环境,如果出现新创建的虚拟环境的名称为空的情况,可以参考添加新创建到虚拟环境到conda env。 # shell conda env list # conda environments: # base /home/ma-user/anaconda3 PyTorch-1.8 /home/ma-user/anaconda3/envs/PyTorch-1.8 python-3.7.10 /home/ma-user/anaconda3/envs/python-3.7.10 sfs-clone-env /home/ma-user/work/envs/user_conda/sfs-clone-env sfs-new-env * /home/ma-user/work/envs/user_conda/sfs-new-env (可选)将新建的虚拟环境注册到JupyterLab kernel(可以在JupyterLab中直接使用虚拟环境) # shell pip install ipykernel ipython kernel install --user --name=sfs-clone-env rm -rf /home/ma-user/.local/share/jupyter/kernels/sfs-clone-env/logo-* 说明:此处“.local/share/jupyter/kernels/sfs-clone-env”为举例,请以用户实际的安装路径为准。 刷新JupyterLab页面,可以看到新的kernel。