miniconda configuration manual – basic configuration, initialization, management of virtual environments, and package operations

Table of Contents

Preface

The first step is to install the software. This step cannot be skipped.

The second step is to configure the basic miniconda. This step mainly involves modifying the “.condarc” file.

The third step is miniconda initialization. This step cannot be skipped.

Step 4. Manage the virtual environment

Step 5: Use the conda command to manage the package. However, if the user still prefers to use the pip command, please read below.

Step 6: The author created some python virtual environments and used the commands for readers’ reference.

Others

Reference link


Foreword

The configuration commands in this article are all DOS commands. Win10 users can use cmd.exe to execute these commands after configuring the miniconda environment variables. At the same time, based on the above reasons, this article adopts a modular writing method.

//The operating system is Window 10
//miniconda version is Miniconda3-py3.10.10_23.3.1

The first step, software installation, this step cannot be skipped

//[conda software mirror download website] https://mirrors.tuna.tsinghua.edu.cn/
//[Please refer to miniconda installation] https://blog.csdn.net/weixin_42968757/article/details/120187522
//After installation is complete, open the installation folder. On the one hand, configure the environment variables (my installation path is E:\Python\Miniconda3, then my environment variables are E:\Python\Miniconda3)
//On the other hand, note that the name of the program file must be "conda.exe". If it is "_conda.exe" or other circumstances, it should be renamed to "conda.exe". Otherwise, enter the "conda" command in cmd invalid. 

The second step, the basic configuration of miniconda, this step is mainly to modify the “.condarc” file

Please refer to the following three links for detailed instructions:
https://blog.csdn.net/weixin_42968757/article/details/120187522 [miniconda installation and python environment construction]
https://blog.csdn.net/m0_45176278/article/details/126670991 [Modify conda default envs_dirs and pkgs_dirs]
https://blog.csdn.net/hshudoudou/article/details/126388686 [Add execution permissions to the envs folder]
The configuration commands given by the author are refinements of the above three articles. Readers can select the configuration commands they need according to their own needs.

/*Basic configuration*/{
/*Set mirror source*/{
conda config --set show_channel_urls yes//Run this command first
//The configuration file is placed in the "C:\Users" folder to view hidden projects that need to be opened.
//Find the ".condarc" file in the "C:\Users" path
//Copy the code in the link "https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/" to the file
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
}
/*Modify conda default envs_dirs and pkgs_dirs*/{
conda config --add envs_dirs E:\Python\Miniconda3\envs
conda config --add pkgs_dirs E:\Python\Miniconda3\pkgs
}
/*Display config information*/{
conda config --show//can display all ocnfig information
conda config --show channels//Display channels information
}
}

The third step, miniconda initialization, this step cannot be skipped

/*Initialization-important steps*/{
//Requires initialization, otherwise activate the virtual environment step and report an error
E:
cd E:\Python\Miniconda3\Scripts
conda init
}

Step 4, Manage Virtual Environment

From this step on, users can focus on building a Python virtual environment.
The author only provides some reference commands, which does not mean that every command is strictly necessary.

/*virtual environment*/{
conda create -n [your_env_name] python=[3.8|3.9|3.10]//Create a virtual environment
conda list -n [your_env_name]//View the installed packages of a specified environment
conda install -n [your_env_name] [package_name]//Install the virtual environment package
conda update -n [your_env_name] [package_name]//Update the package of the specified environment
conda remove -n [your_env_name] [package_name]//Delete the package in the virtual environment
conda activate [your_env_name]//Activate virtual environment
python --version//Check the python version of the virtual environment
conda deactivate//Exit the virtual environment
conda activate [your_env_name]//Switch virtual environment
conda info --envs//View existing environment
//There is a default base virtual environment package here, and its folder path is E:\Python\Miniconda3\Lib\site-packages
/*Rename virtual environment*/{
conda create -n conda-new --clone conda-old//Copy the old environment and reconstruct a name to generate a "renamed" virtual environment
conda remove -n conda-old --all//Delete the old environment
}
conda remove -n [your_env_name] --all//Delete virtual environment
}

Step 5. Use the conda command to manage the package. However, if the user still prefers to use the pip command , please read below

In the reference link provided at the end of this article, there is an article “The difference between pip install and conda install”, which you can read.

/*Package operations*/{
conda list//View all packages installed by conda, the folder path is E:\Python\Miniconda3\pkgs
conda search [package_name]//query
conda install [package_name]//Installation
conda update [package_name]//Update
conda remove [package_name]//Uninstall
conda update --all//Update all packages
//In the virtual environment, these packages on the right: bzip2 ca-certificates libffi openssl sqlite tk tzdata vc vs2015_runtime xz zlib, cannot be uninstalled
}

The sixth step, the author created some python virtual environments, and the commands used are for readers’ reference

/*example*/{
//[Commonly used mirror download websites for python packages] https://pypi.tuna.tsinghua.edu.cn/simple/

conda create -n 1-my Python script python=3.10.10
E:\Python\Miniconda3\envs\1-My Python script\python.exe -m pip install img2pdf Pillow PyPDF2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
conda list -n 1-my Python script --export>package-list.txt

conda create -n 2-data plot python=3.10.10
conda install -n 2-data plot xlrd=2.0.1
E:\Python\Miniconda3\envs\2-data plot\python.exe -m pip install jupyter matplotlib numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/
conda list -n 2-data plot --export>package-list.txt

conda create -n 3-deep learning python=3.9
//[Visit the link to download the whl file] https://download.pytorch.org/whl/cu116
E:\Python\Miniconda3\envs\3-deep learning\python.exe -m pip install torch-1.13.1 + cu116-cp39-cp39-win_amd64.whl
E:\Python\Miniconda3\envs\3-deep learning\python.exe -m pip install torchaudio-0.13.1 + cu116-cp39-cp39-win_amd64.whl
E:\Python\Miniconda3\envs\3-deep learning\python.exe -m pip install torchvision-0.14.1 + cu116-cp39-cp39-win_amd64.whl
//[torch.cuda.is_available() returns false - solution] https://blog.csdn.net/qq_46126258/article/details/112708781
E:\Python\Miniconda3\envs\3-deep learning\python.exe -m pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/
conda list -n 3-deep learning --export>package-list.txt

conda create -n 99-Python-package-test python=3.10.10
E:\Python\Miniconda3\envs\99-Python-package-test\python.exe -m pip install fitz -i https://pypi.tuna.tsinghua.edu.cn/simple/
E:\Python\Miniconda3\envs\99-Python-package-test\python.exe -m pip install PyMuPDF -i https://pypi.tuna.tsinghua.edu.cn/simple/
E:\Python\Miniconda3\envs\99-Python-package-test\python.exe -m pip uninstall fitz
E:\Python\Miniconda3\envs\99-Python-package-test\python.exe -m pip uninstall PyMuPDF
E:\Python\Miniconda3\envs\99-Python-package-test\python.exe -m pip install pyyaml -i https://pypi.tuna.tsinghua.edu.cn/simple/
}

Others

/*Others*/{
conda install pyspark=2.3.0//Install the specified version of the package
pip uninstall xxx//If the conda command fails, you can use pip
conda update python//update python
conda list --revisions//base environment reset
python -m pip freeze >package-list.txt//Record the package names into a text file, the ">" symbol means redirection
python -m pip uninstall -r package-list.txt -y//Delete all packages recorded in the text file
conda list --export>package-list.txt//Record the package names into a text file
conda create -n [your_env_name] --file package-list.txt//Create a virtual environment and install all packages in the text file at the same time
conda update -n base conda//Update conda version
conda install conda=23.5.0//Update conda version
conda clean -a
}
/*Reference link*/{
//[Reference link] https://blog.csdn.net/weixin_42968757/article/details/120187522 [miniconda installation and python environment setup]
//[Reference link] https://blog.csdn.net/m0_45176278/article/details/126670991 [Modify conda default envs_dirs and pkgs_dirs]
//[Reference link] https://blog.csdn.net/hshudoudou/article/details/126388686 [Add execution permissions to the envs folder]
//[Reference link] https://blog.csdn.net/qq_34548075/article/details/119715987 [Powershell, CMD add conda init]
//[Reference link] https://www.cnblogs.com/lynsha/p/13627678.html [Anaconda creates, activates, exits, and deletes virtual environments]
//[Reference link] https://www.zhihu.com/question/395145313 [The difference between pip install and conda install]
//[Reference link] https://juejin.cn/s/conda update and upgrade [The difference between conda update and upgrade]
//[Reference link] https://zhuanlan.zhihu.com/p/37093476 [Correct opening method - ANACONDA and jupyter installation]
//[Reference link] https://blog.csdn.net/m0_46825740/article/details/120932098 [base environment reset]
//[Reference link] https://blog.csdn.net/fei347795790/article/details/128840205 [Delete python package]
//[Reference link] https://zhuanlan.zhihu.com/p/537439636?utm_id=0 [Use of Conda]
//[Reference link] https://blog.csdn.net/weixin_44808890/article/details/124294031 [pkgs file cleaning in anaconda]
}

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Python entry skill treeHomepageOverview 387343 people are learning the system