Deactivating Conda base environment is showing another environment. How do I fix this? - anaconda

Whenever I create a new Tmux session it's activated automatically with base. When I do conda deactivate then it shows that another environment is activated.
For example:
(base) user#something: conda deactivate
(env1) user#something:
when it used to not show anything.
When I run conda env list it shows:
# conda environments:
#
env1 /home/user/.conda/envs/env1
env2 /home/user/.conda/envs/env2
base /usr/local
So something tells me that the base is set incorrectly. How do I fix this behavior?

Related

Conda proxyeroor when shadowsocks opening

I tried to using conda to install tensorflow, but conda show an ProxyError when shadowsocks opening. Though I have configured the proxy_servers in .condarc with the http:\\localhost:port, it did not work. Meanwhile, the direct mode didn't work too. Only I turn off the Shadowsocks, can conda link to channels.
Hers is the Error Message.
ProxyError: Conda cannot proceed due to an error in your proxy configuration. Check for typos and other configuration errors in any '.netrc' file in your home directory, any environment variables ending in '_PROXY', and any other system-wide proxy configuration settings.
How can I use conda normally without turning off shadowsocks?

can't activate anaconda venv that do exist

I'm building a website with Django. I built a Django virtual environment with anaconda. A few days ago I have updated the anaconda and after that, I have a problem with activating a virtual environment
When I trying to activate a virtual environment with source activate django, the terminal responds with this message:
Could not find conda environment: django
You can list all discoverable environments with `conda info --envs`.
where apparently there is a virtual environment name 'django'.
When I try conda info --envs on a terminal, it shows:
WARNING: The conda.compat module is deprecated and will be removed in a future release.
# conda environments:
#
/Users/myname/anaconda3/envs/django
base /anaconda
I can't see the first one's name but only directory. However, if I open anaconda navigator and see the list of virtual environments, I can see the environment name 'django', and can activate it with a play button. Also, I can see one more environment name 'anaconda3' which is not even displayed on a terminal by command conda info --envs.
Is there any possible reason for this?

Updating Anaconda fails: Environment Not Writable Error

I'm trying to update Anaconda and its packages using conda update --name root conda, but it fails every time.
Error message : EnvironmentNotWritableError: The current user does not
have write permissions to the target environment. environment
location: C:\ProgramData\Anaconda3
Environment location: C:\ProgramData\Anaconda3. I replaced the root with base, still I get the same error.
Any help?
start your command prompt with run as administrator
If you face this issue in Linux, one of the common reasons can be that the folder "anaconda3" or "anaconda2" has root ownership. This prevents other users from writing into the folder.
This can be resolved by changing the ownership of the folder from root to "USER" by running the command:
sudo chown -R $USER:$USER anaconda3
or sudo chown -R $USER:$USER <path of anaconda 3/2 folder>
Note: How to figure out whether a folder has root ownership?
-- There will be a lock symbol on the top right corner of the respective folder.
Or right-click on the folder->properties and you will be able to see the owner details
The -R argument lets the $USER access all the folders and files within the folder anaconda3 or anaconda2 or any respective folder. It stands for "recursive".
On Windows, search for Anaconda PowerShell Prompt. Right click the program and select Run as administrator. In the command prompt, execute the following command:
conda update -n base -c defaults conda
Your Anaconda should now update without admin related errors.
Open this folder "C:\ProgramData\" and right-click on "\Anaconda3". go to properties -> security and check all the boxes for each user. This worked for me.
If you get this error under Linux when running conda using sudo, you might be suffering from bug #7267:
When logging in as non-root user via sudo, e.g. by:
sudo -u myuser -i
conda seems to assume that it is run as root and raises an error.
The only known workaround seems to be: Add the following line to your ~/.bashrc:
unset SUDO_UID SUDO_GID SUDO_USER
...or unset the ENV variables by running the line in a different way before running conda.
If you mistakenly installed anaconda/miniconda as root/via sudo this can also lead to the same error, then you might want to do the following:
sudo chown -R username /path/to/anaconda3
Tested with conda 4.6.14.
I had installed anaconda via the system installer on OS X in the past, which created a ~/.conda/environments.txt owned by root. Conda could not modify this file, hence the error.
To fix this issue, I changed the ownership of that directory and file to my username:
sudo chown -R $USER ~/.conda
On Windows in general, running command prompt with administrator works. But if you don't want to do that every time, specify Full control permissions of your user (or simply all users) on Anaconda3 directory. Be aware that specifying it for all users allows other users to install their own packages and modify the content.
I had the same issue and the base environment was in C:\ProgramData\Anaconda3. This is the case, when Anaconda is installed for all users.
As a solution, I re-installed Anaconda just for me and now the base environment is in \AppData\Local\Continuum\anaconda3. This now can be updated via conda update without admin privileges.
As an alternative, I would suggest looking at your conda config file.
Reason
Sometimes for creating a virtual env at a specified location other than the pre-defined path at ~/anaconda3/envs we append the conda config file using: conda config --append envs_dirs /path/to/envs where envs_dirs is a specified function in config file for allocating different paths where conda can find your virtual envs. Removing a recently added path in this config file may solve the problem.
Solution
$:> conda config --show envs_dirs
envs_dirs:
- /home/some_recent_path # remove this
- /home/.../anaconda3/envs
Note the value specifing a different directory other than the predefined location, and remove it using
$:> conda config --remove envs_dirs /home/some_recent_path
Now the config file envs_dirs is set to default location of envs. Try creating a new env now.
this line of code on your terminal, solves the problem
$ sudo chown -R $USER:$USER anaconda 3
WINDOWS:
I also got following error while (base) PS E:\Python> conda install ConfigParser
Verifying transaction: failed
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
environment location: C:\ProgramData\Anaconda3
My solution: Open Command prompt as administrator, then above command again and it worked.
C:\WINDOWS\system32>conda install ConfigParser
Collecting package metadata (current_repodata.json): done Solving environment: done
Package Plan
environment location: C:\ProgramData\Anaconda3
added / updated specs:
- configparser
The following NEW packages will be INSTALLED:
configparser pkgs/main/noarch::configparser-5.0.2-pyhd3eb1b0_0
Proceed ([y]/n)? y
Preparing transaction: done Verifying transaction: done Executing
transaction: done
I had the same problem. The cause for me was that when downloading Anaconda, I chose 'download for all users' instead of 'just for me'. I uninstalled it, re-installed it and corrected that. And I'm not getting this error anymore.
On Windows,
Create a new environment with
conda create --name py35 python=3.5
see conda cheat sheet
Activate this environment
activate py35
Now you don't need to have root access to your new environment.
As mentioned in a comment to the accepted answer, the default environment base requires administrative rights on Windows:
On Windows, if you're trying to install packages into the base
environment (which is installed to C:\ProgramData\Anaconda3), you'll
need admin access. If you first create an environment (which should
install in your user directory under .conda\envs) and activate it, you
no longer need admin right for that environment. Don't forget to
activate the env after creating it. – C.J. Jackson
In my case somehow CONDA_ENVS_PATH was removed, so I was having NotWritableError. So I fixed the error by specifying
CONDA_ENVS_PATH=~/my-envs:/opt/anaconda/envs
in the .bashrc file
I was also suffered by same problem. I resolved the problem by reinstalling anaconda(While installation at this time I selected "just for me" as user) and my problem was solved.Try the same
CONDA UPDATE - NO WRITE ACCESS PROBLEM ## FIXED##
SIMPLE SOLUTION:
Press the Windows+S combination button and type "cmd" into it.
Right click on the Command Prompt App result that shows up and click on "Run as administrator"
Now, in the black window that is open (i.e. your Command prompt), copy and paste the following to check for your version: conda --version
If you want the latest update, then update Conda by running the update command by pasting the following and clicking enter in the command prompt(black window):
conda update conda
If a newer version is available, it will prompt you for a yes/no to install the update. Type "yes" and then press Enter to update.
Deleting file .condarc (eg./root/.condarc) in the user's home directory before installation, resolved the issue.

How to create conda env with both name and path specified

OS: Windows 10
It's fine to create an env with either name or path, but it doesn't work with both name and path:
Command:
conda create -name myname --prefix D:\proj\myconda\myname
Error:
conda create: error: argument -p/--prefix: not allowed with argument -n/--name
So how to create an env both with a specific name and path?
The benefit from that is:
It's more convenient to remember a shorter nick name for the env.
It's better to move the path to other drives to save space of the default C system drive in Windows OS.
create a folder wherever you want to keep you environment files, inside the folder run:
conda create --prefix=yourenvname
When you wish to use this env, move to the folder in which you ran the previous command and do:
source activate yourenvname
Or
You can run:
conda create --prefix=path/yourenvname
This will create environment named "yourenvname" in the specified path.
Create conda environment with prefix:
conda create --prefix=path/to/envname # C:\path\to\envname for Windows users
Make sure that the directory specified is added to envs_dirs configuration
conda config --append envs_dirs path/to/envname # again, change if using Windows
Tip: If you are keeping multiple environments under a directory (e.g. /path/to holds multiple conda environments), then you can
conda config --append envs_dirs path/to # again, change if using Windows
and conda will pick up on all environments stored in /path/to.
After this step, conda should recognize that you want to include envname in your named environments. You can verify with:
conda info --envs
which should return something like:
# conda environments:
#
envname /path/to/envname
Finally, to activate the environment, all you should need to do is
conda activate envname # replace envname with your environment name from prefix

Link old envs to conda

We've just migrated from windows7 to windows10 and had a lot of conda environments associated with each their own experiment.
The envs all exist in, say, F:\backup\<experiment_name>\conda\envs\ and as they were created with conda, conda had them registered. Now - with fresh installs of Anaconda3 we've lost the ease of access from conda as conda info --envs only returns:
D:\>conda info --envs
# conda environments:
#
root * D:\bin\anaconda3
What's the easiest way to get the old envs listed as if they were created with conda? There must be a register somewhere that I could update...?
You can add the backup path to envs_dirs in your .condarc config file.
It can be done with:
conda config --append envs_dirs F:\backup\<experiment_name>\conda\envs\
Or just with a manual edit of the file (it's YAML)
envs_dirs:
- D:\bin\anaconda3\envs
- F:\backup\<experiment_name>\conda\envs\
See the official doc for more details.
In my Anaconda installation on Windows 7 there is a file C:\Users\MYUSERNAME\.conda\environments.txt which contains a plain-text list of the paths of all my environments.
If I create a renamed duplicate of one of these environment folders (say to mynewenv) and edit the new path into the environments.txt file, it appears in the output from conda info --envs and I can successfully (as far as I can tell from a quick test) activate the new environment with activate mynewenv.
That may be enough to sort you out, but if there's anything about the old environments that still isn't registered properly then you should be able to export the environment contents to a .yml file and create a brand new copy by specifying that file to the conda env create command.

Resources