Why is Anaconda source activate non-existent?

2020-07-03 07:27发布

问题:

I successfully created two separate Python environments in Anaconda, yet seem to be unable to activate either one of them. I have tried to read up on this topic as much as possible here on Stackoverflow, yet no solution did resolve my issue. I added information asked for by comments in this question (Anaconda Environment Doesnt activate).

When trying to activate an environment, the console output is -bash: activate: No such file or directory.

The output of which conda is /Users/username/anaconda3/bin/conda. The output of type source is source is a shell builtin. When trying which activate, the shell returns nothing.

In my bin folder, I also seem not to have an activate executable, but only one which is called activate-global-python-argcomplete.

Why do I lack the standard activate file and how I could resolve this issue best?

回答1:

I think you happened to install a buggy version of anaconda which was quickly patched.

conda update conda

should get you back up and running.



回答2:

I experience a similar problem. In my case, the problem is related to the use of the tcsh, but activate only supports bash and zsh.

You can check your current used shell with the command echo $0.

You have to use a compatible shell in order to use the source activate command.



回答3:

Start a new terminal and try again. Alternatively, type hash -r and see if it helps.



回答4:

Do not do this!!!, this broke my dnf

First I tried to point source to a activate file,

source /usr/lib64/python3.6/venv/scripts/common/activate environment

That appeared to work, but no actual values got updated. I tried the answer by mattexx, but it complained conda wasn't installed, so I used.

conda install conda

I had to have root permission since it was being installed to the root environment, but after that everything appears to work.

That is what broke my fedora installation



回答5:

tcsh was the problem for me. Changed to bash and all is ok.



回答6:

In this case, the problem might be that the virtual environment was created in /Users/username/anaconda3/envs/ and hence the activate will be in: /Users/username/anaconda3/envs/NAME_OF_YOUR_VIRTUAL_ENV/bin/activate

Hence to activate the environment you could run:
source /Users/username/anaconda3/envs/NAME_OF_YOUR_VIRTUAL_ENV/bin/activate



回答7:

My problem was that file /opt/pycharm/plugins/terminal/.zshrc (using ZSH) contained line source $JEDITERM_SOURCE. That variable contained correct paths as two parameters <path-to-anaconda-activate>/activate <path-to-anaconda>, but apparently they got interpreted as a single parameter: <path-to-anaconda-activate>/activate <path-to-anaconda>.

I solved that prepending eval to that line, making it eval source $JEDITERM_SOURCE. Now, the variable expands correctly.

If you're using bash then make the same change to /opt/pycharm/plugins/terminal/jediterm-bash.in.



回答8:

I'm using the bash shell inside pycharm and fixed the problem by making this change:

[~/opt/pycharm-community/plugins/terminal]$ diff jediterm-bash.in.old jediterm-bash.in
65c65
<   source "$JEDITERM_SOURCE"
---
>   eval source "$JEDITERM_SOURCE"

Essentially making the same change recommended above by https://stackoverflow.com/users/1564931/netchkin, but to ~/opt/pycharm-community/plugins/terminal/jediterm-bash.in.

This fixed my existing projects. But any new projects don't seem to try and activate the conda environment at all. It seems as if new projects created in Pycharm 2017.1.2 don't set the JEDITERM_SOURCE variable when starting a session in the terminal plugin.

There is an open issue on this at https://youtrack.jetbrains.com/issue/PY-23417

Looks like there was a big change to the conda activate script in version 4.4.0. See https://conda.io/docs/release-notes.html. If I downgrade conda to 4.3.34 then I can get conda virtual environments to work in the pycharm terminal again.