});

Some cool hacks with the native conda configurations.

miniconda transplant

Motivation: cloned a entire miniconda and transfer it to a new user.

Steps:

  1. replace all directory in conda config --show using conda config --set %var%name %value%name, may use conda init to update. Use conda info | grep %old_dir% to double check.
  2. Change the directory in %/old/dir%/miniconda3/etc/profile.d/conda.sh then source the conda.sh to update env. Although I find conda init overwrite it immediately.
  3. replace all directory in ~/.bashrc under the block conda init
    Hint: can use sed -i 's@/old/dir/@/new/dir/@g' ~/.bashrc. Note that sed replace pattern can use any delimiter, such as the @ here, not just /.
    And do source ~/.bashrc to update

Step 1 is the key, and step 2 and 3 are mainly for switch to the right conda.sh, and they might be rewritten in no time. These steps may need more investigation but they temporary meet my demand. Let me know your comments and advice if find anything wrong or can be improved.

If you also have jupyter, you may also need to:

  1. jupyter lab --generate-config and nano ~/.jupyter/%lab_config% to change .root_dir, .ip, .passwd, etc.

Run Python of Conda with Win Bat

Why not just use the light and pure python IDLE?

The idea

Activate the environment, query the root directory of current python and run its idle within the activated environment, so that the packages are usable.

The idle.bat has to be run under the CMD with desired environment activated, else most packages will be unavailable.

For a quick start, a bat file can be written as shown below.
Notice that we use call * to aviod interruption of current .bat file,
for that the activate and workon file is also .bat file and running of a new .bat file will interrupt the current .bat process.

Source Code

Reference:

【利用bat切换虚拟环境】
【bat基本语法】
【bat文件中文运行乱码】如果遇到乱码,记事本另存为ANSI编码方可支持中文编译
【.bat进行java-sdk环境切换】 at CSDN.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.