Why does '(base)' appear in my anaconda command prompt? - python

My anaconda command prompt now says:
(base) C:\users\user_name>
I would like to know why (base) appears in front of the prompt. This started appearing since I created a virtual environment to run Django. If I enter 'deactivate' the prompt disappears but if I close the terminal and open a new terminal the 'base' is back again.
(base) C:\users\user_name> deactivate
C:\users\user_name>
The trouble is that this prompt does not recognize pip or any anaconda commands. I can run pip on the 'base' prompt, but not on the original one. I installed a module in '(base)...' using pip but this module is recognized by my ide.
conda list anaconda
in '(base)..' gives th version of Anaconda as 4.4. without the base, it does not recognize conda. I have run pip and conda several times before this happened. I'm running Windows 10.

Try this:
conda config --set auto_activate_base false
The changeps1 only hide the command prompt, you still in this environment.
auto_activate_base can avoid entering the environment.

Although Blockchain Business's answer is correct, as of v 4.6.4
DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
so,
conda deactivate
This actually deactivates Anaconda completely, so may not be the best solution...
To restore:
conda activate

Change command prompt (changeps1) in ~/.condarc:
changeps1: False
Reference:
how to modify conda 'source activate' ps1 behavior
Document:
https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#change-command-prompt-changeps1

"(base)" is displayed to tell you which environment you are in. "base" is the default environment.
You can create a new environment from within Anaconda Navigator. You might do this to run a different version of python, perhaps, for example, because a library you wish to use is only compatible with python 3.6 or lower.
Also if you want to install an experimental library/package and not have it break your other installed packages, you might install it in a new environment, where it is isolated from the rest of your installed libraries/packages.
You are probably best to use the Environments tab in Anaconda Navigator for the creation, management of environments and installation of libraries/packages, but you can use the Anaconda Prompt commands if you like and on some machines it is a lot faster to do so.
Be aware that although pip install and conda install commands are supposed to play better together these days, I would still recommend sticking to conda install and only using pip if conda install won’t work for a particular package. This is because installing python packages so they do not conflict with one another is apparently not so trivial - and using two different package managers could be a problem. In the old days pip was almost certain to break environments that had been set up with conda or Anaconda Navigator.

If you face the issue in Ubuntu you can try the below two steps to remove it from your command prompt.
conda config
conda config --set changeps1 False

I had the same issue, I typed the following command to remove the (base) reference:
source deactivate

In my case, I had run source ~/anaconda3/etc/profile.d/conda.sh and expected the env to get activate.
Instead it must be conda activate

type 'conda deactivate' in the working terminal.

It sounds like when you installed Anaconda, it's now seeing that as your default environment, and with Anaconda it's best that you install packages using conda rather than by using pip, because at best pip installed packages won't be recognized by Anaconda, and at worst the pip installed packages can break your Anaconda install. I went through some of this before myself, as I needed to use Anaconda for a Python course I was taking, however I use Kubuntu, so I don't have a lot of knowledge around using it on Windows.
For more info on using Anaconda, see https://conda.io/docs/user-guide/getting-started.html You can probably use Anaconda Navigator to create virtual environments and install packages too.

Showing the active environment in front of the path like (base) C:\users\user_name> is a feature, not a bug. If you pip-install a module into the base environment (bad practice warning: Use conda install this_module -c conda-forge or pip install this_module into a separate environment), you'll first need to activate the base environment before you can actually use this_module. If you don't know how to do this in your IDE (although this a base functionallity of any IDE), open a cmd shell, type conda activate and then start your IDE directly from the (base) C:\users\user_name> prompt.

Related

Why isn't Anaconda working inside of one of my Conda environments while using Ubuntu LTS?

I'm not sure why I can't get Anaconda to launch while I'm inside of one of my Conda environments; I'm using Ubuntu LTS. While I'm in the base environment, I can run the following command in my terminal and Anaconda will start up just fine.
anaconda-navigator
I also set up a Conda environment with specifications for a specific version of python and specific versions of libraries in a .yml file; conda was able to download and install everything successfully. When I run the below command in my terminal, I can see that the environment changes.
conda active {environment name}
My problem is that when I try to start up anaconda while inside of this new environment I get a command not found message.
How do I fix this error?
This is the intended behavior - anaconda-navigator is only meant to be launched from base environment. When base is not active, only the condabin/ directory from the base environment is still retained on $PATH. If you really want to launch Anaconda Navigator from other environments, you could try creating a symlink/softlink pointing at the base bin/anaconda-navigator, e.g.,
conda activate base
cd $CONDA_PREFIX
ln -s bin/anaconda-navigator condabin/anaconda-navigator
However, this is non-standard and may lead to unexpected behavior.
Otherwise, you would need to install anaconda-navigator in each environment, which I don't think is recommended.

Python interpreter is in a Conda environment, but the environment has not been activated

Installation:
I'm a newbie in Python and I'm facing issues with Anaconda. Whenever I launch Anaconda Navigator it shows Python stopped working and crashes.
Also if I type python in the command prompt I get a warning:
"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"
I have seen such questions before and tried the solutions, but nothing seems to work. I also tried to reinstall, but it's the same every time.
Try:
conda activate base
Or create a venv:
conda create my_env
conda activate my_env
Or install the Python system directly. Download from here.
This seems to be two separate issues:
Crashing on Anaconda Navigator startup
Try to update PyQt. For more information, see: Spyder and Anaconda Navigator do not open - "Python has stopped working" (Fixed) #10088
For the Python commands, try to activate your environment: conda activate base.

Python Virtual Environments Confusion

I have been learning data science using python for about a year now. I have become quite comfortable with the syntax and model creation. I have exclusively used Google Colab just due to how convenient it is and I love the notebook style. However, one thing I do not understand is the environment stuff. Although I use Colab, I do have python and anaconda on my machine and have installed various packages using the exact following format: pip install (package name). When I open my terminal, the first line is lead with (base) and when I check the Environments tab in anaconda navigator, it appears as though I installed all of these packages into a base environment named base (root)? Is that right? If so, what would my environment's name be then? What is a base environment compared to a venv?
The reason I am asking is because if I ever decide to use an IDE in the future, I would need to set my environment to be able to run packages, correct?
Just for fun I want to try using R and its reticulate package that allows python use in R. As stated in the answer to this question, I need to set my virtual environment before I can use python in R. Would my virtual environment be base (root)?
I'm a complete noob about all of this environment stuff. Again, I just opened my terminal and typed pip install (package name) for all packages I've installed. Thanks for any help in advance.
So from your description, it sounds like your default Python installation on your computer is through Anaconda. If that's the case, base is actually going to be the name of the conda virtual environment that you're using.
Virtual environments can be tricky, so I'll walk you through what I usually do here.
First, you can always check which Python installation you're currently using by using the which command on Mac/Linux, or if you're using Windows the command will probably be where (if you're on Windows, this answer might be helpful: equivalent of 'which' in Windows.)
(base) ➜ ~ which python
/Users/steven/miniconda3/bin/python
From the above, you can see that my default Python is through Miniconda, which is just a small version of Anaconda.
This means that when you use pip to install packages, those are getting installed into this base conda environment. And, by the way, you can use the which command with pip as well, just to double-check that you're using the version of pip that's in your current environment:
(base) ➜ ~ which pip
/Users/steven/miniconda3/bin/pip
If you want to see the list of packages currently installed, you can do pip freeze, or conda env export. Both pip and conda are package managers, and if you're using an Anaconda Python installation then you can (generally) use either to install packages into your virtual environment.
(Quick side note: "virtual environments" are a general concept that can be implemented in different ways. Both conda and virtualenv are ways to use virtual environments in Python. I'm also a data scientist, and I use conda for all of my virtual environments.)
If you want to create a new virtual environment using conda, it's very straightforward. First, you can create the environment and install some packages right away, like pandas and matplotlib. Then you can activate that environment, check your version of python, and then deactivate it.
(base) ➜ ~ conda create -n my-new-environment pandas matplotlib
(base) ➜ ~ which python
/Users/steven/miniconda3/bin/python
(base) ➜ ~ conda activate my-new-environment
(my-new-environment) ➜ ~ which python
/Users/steven/miniconda3/envs/my-new-environment/bin/python
(my-new-environment) ➜ ~ conda deactivate
(base) ➜ ~ which python
/Users/steven/miniconda3/bin/python
And, if you want to see which conda virtual environments you currently have available, you can run conda env list.
Here's the documentation for conda environments, which I reference all the time: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
I hope this is helpful!

How to still using anaconda Python3 after activate a conda environment?

I'm using MAC OS and installed python2, then miniconda python2, and then Anaconda python3.
Now normally in terminal my python version would be python3, but if I activate a conda environment "test", then the default python will be python2.
I believe the reason is the $PATH is changed, at "base" env (when terminal started), the starting part is "/anaconda3/bin:/anaconda3/condabin", and after "conda activate env", it changed to "/anaconda3/envs/test/bin:/anaconda3/condabin" which do not have python3 in those bin folder.
Is there a method to make the conda environment using the python3 of Anaconda?
I tried to create a link (both symbolic and hard) /anaconda3/envs/test/bin/python -> /anaconda3/bin/python. By this way, anaconda python3 can be started inside conda env. Then I found pip still not reachable. I think may create a pip link file too. But I guess this is not the correct way to use a conda environment?
(base) $which python
/anaconda3/bin/python
(base) $which pip
/anaconda3/bin/pip
(base) $conda activate test
(test) $which python
/usr/bin/python
(test) $which pip
'''no result'''
I expect the created conda env to use the same python3 as in base env, and can use pip, without setup symbolic or hard link.
When you activate a conda environment, you'll use the Python version from that environment. pip will automatically install into the active conda environment, unless you do something to break it, for example by calling another pip installation than the one from the current environment.
If you want to use a different Python, then don't activate the conda environment. If you want to use a specific version of Python in an environment, then install that version into that environment. Inside an environment, you can only (reasonably) use the Python version that's installed in the environment.
By the way, it is pointless to install different versions of Anaconda or Miniconda alongside. Just install Miniconda and create conda environments for everything else. Install the package anaconda into an environment to get the packages that Anaconda brings along.
I think you have added the path of "/usr/bin/python" in $PATH by anyway. So while doing python from inside a specific conda environment you are redirected to use the "/usr/bin/python" instead of "/anaconda3/bin/python". You can check the path by
$ $PATH

How to install Python packages in a specific environment?

I installed Anaconda3 so I can create environments and install different packages in each environment. But I fail to understand the difference between the Python in
/usr/bin/python
and
/opt/anaconda3/bin/python
I can seem to access Python 3.6.5 Anaconda from both, why is that? And, what is the difference between both?
Furthermore, I would like to install packages to a single Python environment only.
When you are running python in the terminal, it is looking up your default path to your the python command. In this case, anaconda probably put a line in your shell profile specify the path to the anaconda version, which is why you are seeing it in the interpreter when you run python from either directory.
Secondly, you can set up a conda environment to download app specific dependencies without interfering with your default set up by
conda create --name myenv
source activate myenv
conda install packagename
This will install it in the myenv environment only. To deactivate the environment just run
source deactivate
Here is the documentation on that https://conda.io/docs/user-guide/tasks/manage-environments.html
Judging by your path, you are using Linux which comes with python installed. So /usr/bin/python is default and you have installed the other one later.
For the environments use https://conda.io/docs/user-guide/tasks/manage-environments.html to activate the desired environment, then you can pip install or conda install the packages and it will be places safely only in that environment. Note that spyder icon runs the root environment by default and you have to run it from terminal after activating one of the environments.
Edit:
I'm not sure why you want to use cd to change the python version. I suggest use aliases. I guess you are just changing the path but running the same version of the python anyway. Take a look at this question:
Two versions of python on linux. how to make 2.7 the default
I wanted to create a new virtual environment to install new packages. Following worked for me:
Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)
Upgrade pip:
!pip install --upgrade pip
Install virtual environment:
!pip install virtualenv
Select version of Python you want to use in new environment:
I wanted to create an environment with Python version 3. Naming it as Python3_xyz:
!virtualenv -p python3 Python3_xyz
After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)
Create a new option with the name of the created environment
And finally, run the following command:
!python -m ipykernel install --user --name=Python3_xyz
This will create a new option with the name Python3_xyz in the menu from where we create a new notebook.
NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.
This question is bit dated, but since I faced a similar issue, what worked for me might help someone!
I did pip install requests from within my conda environment, but failed to import requests even after trying out everything.
What worked for me: run python -m pip install requests or python3 -m pip install requests within you environment. This installed requests successfully for me.

Categories