Conda installs packages on the base environment only - python

I have Conda 4.7.11 and system python 3.7.3 (base) on MacBook. Whenever I try to install new packages on the environment that I have created, Conda installs them on the base instead.
I have activated the environment and when I type python on the Terminal, I get the correct python version of my env (3.6.9). Also, which python points me to the correct python path: /anaconda3/envs/Bayesian_Models/bin/python
But, if I type conda info, when my env is active, then I get this (python 3.7.3):

Workaround
I'm not sure how to fix the issue permanently, but specifying the env using the --name|-n tag could get around the problem:
conda install -n Bayesian_Models foo_package

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.

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

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

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.

Importing a package installed with anaconda in virtual environment

I want to work with the python package holopy. Apparently you have to use conda to install it, so I first installed Anaconda 4.2.0 (since I'm using Python 3.5). I opened the virtual environment I normally use and installed holopy as they recommend on the official site:
conda install -c conda-forge holopy
Afterwards, when in the virtual environment I type conda list, holopy shows up. But when I type python3 and then import holopy, it says package not found. It does however work when I leave the virtual environment. I need it in the virtual environment though, how can I do that?
I'm not sure how well anaconda and virtual environments i.e.venv work together. If you're using anaconda anyway then I highly recommend using anaconda environments. Please go through this short tutorial about anaconda environments - you won't regret it.
Why it didn't work for you?
The conda command is available only in the base anaconda environment. So when you run the command - conda insall -c conda-forge holopy, it installed holopy in the base anaconda environment and it won't be available to you in your venv.
After looking at the documentation of holopy it seems probable that when they said virtual environment they actually meant anaconda virtual environment. Therefore the solution is to first create an anaconda virtual environment called holopy-env and then run the command conda install -n holopy-env -c conda-forge holopy.
A better way of doing things with Anaconda
I will also give you a quick and clean example of how to create an environment using anaconda. If you're using Anaconda then it would be wise to use it's environment management tools. Create an environment.yml file with the following contents:
environment.yml using conda-forge/holopy & python 3.6
name: holopy-env # any name for the environment
channels:
- conda-forge
dependencies: # everything under this, installed by conda
- python=3.6
- holopy
- pip: # everything under this, installed by pip
- future
How to install the environment?
conda create --force -f environment.yml
How to activate the environment?
source activate opencv-env
After activating the environment
You should be able to import holopy
Install pip packages using pip install <package>
Install conda packages using conda install -n holopy-env -c CHANNEL <package>
conda is a packaging tool and installer that aims to do more than what pip can do; handle library dependencies outside of the Python packages as well as the Python packages themselves. Conda also creates a virtual environment, like virtualenv does. For creating virtualenv with conda, use the following command:-
conda create -n yourenvname python=x.x anaconda
Use the following to activate the virtualenv in conda
source activate yourenvname
Then, you can install the packages in virtualenv using conda as:-
conda install -n yourenvname [package]
To Deactivate use:-
source deactivate
And to delete a no longer needed virtualenv, use :-
conda remove -n yourenvname -all
I know this is a bit late, but you don't need to use conda to install HoloPy. This is just the least technical option. Otherwise, you need to be able to compile HoloPy's fortran components yourself, which is fairly straightforward on Unix-based systems but complicated on Windows. Instructions can be found in HoloPy's documentation at https://holopy.readthedocs.io/en/latest/users/dev_tutorial.html.
We are also working on putting together a singularity container distribution of HoloPy. Let me know if this is of interest to you and I will make it a priority.

Conda virtual environment not working properly in Anaconda 5.1

I installed the latest Anaconda and installed it with default values.
After that, I tried which python and it's giving me correct python paths for Anaconda5.1 Python2.7 versions ~/anaconda2/bin.
Now when I create a virtual environment using the following command:
conda create -n new_env python=2.7 opencv numpy pandas
&
source activate new_env
When I do which python now I get the new virtual environment python ~/anaconda2/envs/new_env/bin/python which is good. But when I do which conda I get the base anaconda conda ~/anaconda2/bin/conda not the virtual environment conda path. In previous versions, it wasn't like this.
Am I missing something here?
p.s. I tried with Anaconda5.1 for Python3.6 also, the same result.

Categories