Why do I need to activate conda and my venv every time i open cmd? Is this normal?

Viewed 3015

I'm super new to programming, i'm trying to learn how to create a project, make venv, and activate it.

Question 1: do i have to activate the conda env every time i open command prompt?

If i open cmd and type in "python" i get this message:

Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>>     

I type in "conda activate" and everything is cool and good. If i close cmd and open it again, it acts as if I never activated conda and gives me the same message again. Is this normal? Do i have to activate the conda env every time?

Question 2: what's the difference between (base), (env), and (base) (env) and why does the following happen?

I followed a tutorial for making a python project, making an env in command prompt, and activating it with "env\Scripts\activate.bat" and got the (env) output. Then i closed cmd, opened it again, and if i navigate to the path where my example env lives, it doesn't say (env) in front of it.

D:\>cd D:/Favorites/1. Programming/LearnPython/PracticeProject

D:\Favorites\1. Programming\LearnPython\PracticeProject>python
Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

D:\Favorites\1. Programming\LearnPython\PracticeProject>env\Scripts\activate.bat

(env) D:\Favorites\1. Programming\LearnPython\PracticeProject>python
Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

(env) D:\Favorites\1. Programming\LearnPython\PracticeProject>conda activate

(base) (env) D:\Favorites\1. Programming\LearnPython\PracticeProject>python
Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>                                                                                                               

I'm sorry that this is really basic. After trying to research this for 2 days i'm kind of lost. I'm at the level where I'm struggling with step 0 of starting a project. Am I supposed to activate whatever env i need every time I open command prompt? Am i supposed to activate venv every time i want to work on the project even if I don't open cmd? Is the fact that my venv doesn't stay activated a problem? What dies (base) mean?

1 Answers

Environments are an important part of Python, especially if you're working on multiple projects with separate dependencies.

...For example if project_a uses Python 2.7, but project_b uses Python 3.6 you would want two separate environments or you're guaranteed to have dependencies issues and an immense headache.

Question 1: do i have to activate the conda env every time i open command prompt?

No, you do not have to activate conda every time you open CMD. This is simply a matter of choice for the developer. That being said, if you are working on a Windows machine and exclusively using a singular Conda environment, you might find it easier to start the Anaconda Terminal rather than starting CMD and having to activate your environment everytime.

If you are frequently switching between environments, than you'll likely be better off starting and stopping you Conda or Python Environments from CMD...again matter of choice.

Question 2: what's the difference between (base), (env), and (base) (env) and why does the following happen?

What you have here are two different environments. Where I assume that base is a Conda Environment and env is a Python Virtual Environment.

If you wish to know more about more about the difference between the two, the following article may be a good place to start https://www.anaconda.com/understanding-conda-and-pip/

Related