Anaconda (python)

Creating new conda environment 

To create a new conda environment, you can use the `conda create` command followed by the `-n` (or `--name`) option and the name of the environment. For example, to create an environment named `myenv`, you can use this command:


```bash

conda create -n myenv

```


By default, this command creates an environment with only the bare minimum packages. If you want to include specific packages when you create the environment, you can specify them at the end of the command. For example, to create an environment with Python 3.8 and NumPy, you can use this command:


```bash

conda create -n myenv python=3.8 numpy

```


After you've created the environment, you can activate it using the `conda activate` command:


```bash

conda activate myenv

```


Once the environment is active, any packages you install with `conda install` will be installed in this environment, and Python will use this environment for its packages.


When you're done with the environment, you can deactivate it with the `conda deactivate` command:


```bash

conda deactivate

```


Remember that you'll need to reactivate the environment every time you start a new session and want to use it.

How to check all the conda environments I have?

You can see a list of all your conda environments by using the `conda env list` command or its shorthand version `conda info --envs`. Here's what the command looks like:


```bash

conda env list

```

or

```bash

conda info --envs

```


This command will print a list of all your environments. The environment you're currently in will be marked with an asterisk (*). The output will also show the directory associated with each environment.

How to delete conda environment?

To remove or delete a conda environment, you can use the `conda env remove` command followed by the `--name` option and the name of the environment. For example, to delete an environment named `myenv`, you would use this command:


```bash

conda env remove --name myenv

```


Please make sure you are not currently in the environment you want to remove. You should switch to another environment or deactivate the current environment using `conda deactivate` before attempting to remove it.


Shifting from anaconda to miniconda, elegantly

Shifting from Anaconda to Miniconda is essentially a process of removing Anaconda and installing Miniconda. However, before doing that, make sure you save any project specific environments or dependencies that you want to use later in Miniconda. 

Here's a step-by-step guide:

1. **Export Your Current Environments**: You may want to save your existing Anaconda environments so that you can recreate them in Miniconda. You can do this by listing your environments with `conda env list`, then exporting each one with `conda env export -n myenv > myenv.yml` (replace `myenv` with the name of your environment).

2. **Uninstall Anaconda**: You can uninstall Anaconda via the 'Add or Remove Programs' section in Windows. Search for Anaconda, and click 'Uninstall'. 

3. **Delete residual files**: Anaconda leaves behind some residual files. You'll want to remove the Anaconda directory, which should be located in your user directory. For example Anaconda or Anaconda3 or .conda file in your C:\Users\<Your User Name>.  Also remove any lines referring to Anaconda in your .bash_profile or .bashrc file if you've added them.

4. **Install Miniconda**: Download the Miniconda installer from the official website. Choose the Python 3.x version. Run the installer, and when prompted, choose to add Miniconda to your PATH and to make it your default Python.

5. **Recreate Your Environments**: Use your exported .yml files to recreate your environments in Miniconda. You can do this by running `conda env create -f myenv.yml` (replace `myenv.yml` with the name of your file).

6. **Reinstall Packages**: For any packages you installed with pip instead of conda, you may need to reinstall them in your new Miniconda environment. You can do this by activating the environment (with `conda activate myenv`), then using pip to install the packages.

Remember, always backup your important data and code before doing these steps to ensure that you don't lose anything accidentally. 

Lastly, shifting to Miniconda will likely make your base environment much smaller and less cluttered, but the environments you create can still access the full suite of packages from the Anaconda distribution. In the end, the only major difference between Anaconda and Miniconda is the size and number of packages they come with by default.

Adding a local module in python path

In anaconda command prompt, Activate your environment and do the following-

set PYTHONPATH=%PYTHONPATH%;C:\path\to\directory

Run this command in windows command line for the windows python.


Comments