Using conda pack for environment migration

origin

The reason is that the training server is restricted from accessing the Internet during the security period. Moreover, the training server that wants to connect to the A100 graphics card must be connected through the bastion host (that is, the target server cannot be connected to the Internet, nor is it in the same network segment as the local machine)

Installation tools

First, use conda env listto view all environments. Make sure that the environment to be migrated is not the default base environment (if it is a base environment, use the conda clonecommand to copy it to another name)

Then activate the environment to be migrated. My environment here is named chatGLM, so the corresponding activation command isconda activate chatGLM

Then use the pip command to installpip install conda-pack

picture.png

Pack the original environment

Use conda pack -n <环境名>to package the environment (the packaging speed is quite fast), and a tar.gz file will be generated after packaging.

picture.png

It only took me 3 minutes to pack up the environment that I had installed for a day.

picture.png

Upload the virtual machine environment to the local machine

Note: Both environments must be the same system. For example, my local computer is centos, and the target host is also centos (if your local computer is window, the installed package may not be applicable to centos, which will cause it to not work properly after migration)

Although my native machine is Widnows, I used Virtual box to build a centos virtual machine, installed anaconda in the virtual machine, and then used pip to install the respective dependencies.

Option 1: Upload sz directly

File upload/download commands supported by Tabby terminal

  • sz: ZModem protocol to transfer files from Linux server to local
  • rz: To upload files from local to Linux server, you can use the rz command

Use sz <待拉取的文件路径>to pull files to local

picture.png

Option 2: After splitting and slicing, upload sz

Note: The file is relatively large. The sz command may report an error after all transmissions are completed. You can use splitthe command to split it.

split -b 512M -d -a 1 chatGLM.tar.gz
  • -b 4096M The size of each compressed package divided is 4G
  • The -d parameter specifies that the suffix of the generated segmented package is in the form of a number.
  • -ax to set the length of the sequence (the default value is 2), here the length of the sequence is set to 1

picture.png

After switching to 512M, it can be uploaded, but occasionally an error will still be reported, which is very inconvenient. Although wildcards are supported, you will still be asked for the folder you want to save every time (you cannot set it once, and the folder will be used by default later, which is inconvenient)

picture.png

Solution three: Virtualbox installs auxiliary plug-ins and shared folders

Virtual cannot directly install the enhanced assistant, even after referring to several blogs, I succeeded after following this article. The address is: https://zhuanlan.zhihu.com/p/633877183

Except for Chinese garbled characters, English is normal (using Tabby or XShell to connect, there will be no garbled characters problem)

picture.png

Then use mvthe command to copy the file to the shared directory. After copying, switch to the window side and see that it appears instantly (much faster than the previous sz command)

picture.png

Upload the local environment compressed package to the target server

Tabby then switches to the target server and rzuploads the file to the server using the command

Delete the environment with the same name on the target server

Now come to the target host and use conda env listto view all current environments

Then use conda env remove -p <环境路径>to delete the environment with the same name

picture.png

restore environment

Then conda env listlist the paths to all virtual environments using

picture.png

Here, the environment variable path of anaconda3 is:/opt/anaconda3/envs/

Create a new folder with "virtual environment name" under this pathmkdir /opt/anaconda3/envs/<虚拟环境名>

All permissions will then be givenchmod 777 /opt/anaconda3/envs/<虚拟环境名>

Then decompress the compressed package just uploaded to this directory and use the following command

tar -xzvf <环境变量压缩包>.tar.gz -C /opt/anaconda3/envs/<虚拟环境名>

View Results

After modification, use conda env listto view the environment just added

picture.png

Then use conda activate <虚拟环境名>to activate the environment variable

picture.png

Use conda listthe command to check whether all the libraries we installed before exist.

picture.png

Guess you like

Origin blog.csdn.net/chy555chy/article/details/131832702