Basic Conda Usage


Preface


Long time no see. This bolg is written for record the knowledge I've learnt during installing pytorch on windows. And I'll introduce some basic knowledge about virtual environment, update and etc. Attention that these command or method is suit for windows, most of them will be suit for linux.

Check the pagkage's location


It's really import for me to confirm where the file/program consume the space of my disk. To check the python module package's path. You can try this:

import module
print(module.__file__)

In general, ananconda's package will be installed follow this path [your anaconda's directory]\Lib\site-packages

Virtual Environment


Creating virtual environment aim to better run other's python program which may have difference among their version. What's more, programming in a virtual environment will prevent the conflict among the global python module.

Create


conda create -n my_env_name python=3.6

On windows, run this command on cmd, and you will create a new virtual environment with the name you replace at my_env_name.

Check your virtual environment


Check your virtual environment's list in this way:

conda info --envs

or this way

conda env list

Activate your Virtual Environment


conda activate my_env_name

This command will help you enter into the correspond virtual environment. Normally, your terminal will look like this:

(my_env_name)[user_name](blablabal..)

Quit the Current Virtual Environment


conda deactivate

Some blogs resquire your env_name after the deactivate, however I've find some error about this method. And I find this solution from an github issue. It suits my condition well.

Install Package At The Specific Virtual Environment


One of the virtual environment's advantages is that you can install your package without considering the potential conflict among the global package. You can install your package, and its effect domain will be constrained into the specific virtual environment.

conda install -n my_env_name [package]

or you can activate the specific virtual environment and use pip install at current virtual environment.

Remove the Virtual Environment


conda remove -n my_env_name --all

This command will remove my_env_name virtual environment.

Remove the Package In the Virtual Environment


conda remove -n my_env_name package

warning: still unsure this command

Handle the global package


Check the installed global package:

conda list

Install global package:

conda install package

Configure yml file to create a new environment


Example yml file:

name: my_env_name
dependencies:
- python=3.6
- pytest
- keras
- tqdm
- Pillow
- pip:
    - tensorflow

Warning: I'm not quite sure about this method.

Then you can create a new virtual environment by this command:

conda env create -f env_config.yml

Share Your Environment


Export your Environment yml file


conda env export > [environment yml file name].yml

Clone your Environment


conda create -n [new environment name] --clone [existed environment name]

What's more


For the command that you are not familiar with, you can check it's usage by add a -h at the end of the command.

Some blogs

conda usage


Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Tom.Eureka.Newton !
  TOC