Conda env activation: Weird "must be sourced" error - bash

I am trying to run the following:
source activate env-name
But I am receiving an error that tells me that the call to activate must be sourced. In the Conda activate script, there's an if block near the beginning that tests "$(basename "$0")", specifically whether it's equal to activate, in which case it will raise the exception I'm referring to. A little bit of fiddling with the script (i.e., echo $0; return 1) and I found out that it does indeed think that the 0th argument that I am passing in is activate rather than source. This is perplexing because I know that my command includes source in it and that that should be the 0th argument. I'm not sure what else there is to do. Does anybody have any clues?
In case it's important, I am using zsh as my default shell and it seems that the activate script is a bash script, but I don't think that should matter (it doesn't elsewhere for me, only in this specific environment on my work laptop). I am able to get around this whole thing by just commenting out the whole check (and a couple of other minor changes), but I'd rather not have to do that in this particular case.

I've been having the same issue, the only workaround I've found is:
source <PATH TO ANACONDA>/anaconda3/bin/activate <ENV NAME>
EDIT: adding the line:
export PATH=$PATH:<PATH TO ANACONDA>/anaconda3/bin:$PATH
to your bashrc (or zsh etc) will add source to your path and you will be able to use source as normal.

** I DON'T HAVE ENOUGH REPUTATION, SO I REPLY THIS. (I wanna just comment but I can't)
It can be solve that you know this.
"Run 'Source activate envname'" means you have to run this command on correct path or directory.
If you install anaconda3 on /home/user/anaconda3/
your correnct source path is /home/user/anaconda3/bin/
/home/user/anaconda3/bin/ activate tensorflow
or
cd /home/user/anaconda3/bin
. activate tensorflow
So, I already solve this problem through adding path(or move correct path)

I got similar error because I was using asdf-vm which masks actual binaries with shims. As documented here, scripts that need to be sourced must be accessed directly because asdf uses exec system call. So in my case, the following command worked:
source $(asdf which activate) <ENV NAME>
While this answer is specific to asdf, the error you're getting suggests you were in a similar situation where the call to activate was intercepted by some other executable.

Related

Trouble installing haskell: how to adjust PATH variable to add to a shell config file?

I installed Haskell on my MacOS system using ghcup installer. It worked because if I type ghci I am dropped into this interactive shell. However I got this message in the terminal after doing the install:
In order to run ghc and cabal, you need to adjust your PATH variable.
You may want to source '/Users/user1/.ghcup/env' in your shell
configuration to do so (e.g. ~/.bashrc).
Detected bash shell on your system...
If you want ghcup to automatically add the required PATH variable to "/Users/user1/.bashrc"
answer with YES, otherwise with NO and press ENTER.
YES
grep: /Users/user1/.bashrc: No such file or directory
My shell is bash 3.2 But as you can see, when I typed YES it says there is no such file. How do I find my shell configuration file, or resolve this? I'd like to complete the setup correctly here.
And I have to be honest about my level of knowledge here, I don't truly understand what this is asking exactly. Is the PATH variable 'env'?
On macOS, .bashrc does not exist by default. ghcup will create this file, so the command you ran will have worked correctly. However, one of ghcup's subcommands expected to find the file before it was created, and therefore reported that error message. You can safely ignore this.

source /.bash_profile command not working

I am trying to refresh my aliases on my Mac (OS Catalina 10.15.6) after defining new aliases in my .bash_profile file with the command:
source ~/.bash_profile
But terminal keeps giving this error message:-bash: s: command not found
This is confusing because for the longest time this command worked. I even had it included in my .bash_profile file as an alias, where it worked fine.
I'm aware the problem could have to do it with an error in my PATH but I've never made any edits to my PATH so have no idea what the issue could be?
Thanks in advance.
My first instinct would be to check both ~/.bashrc, and /etc/bashrc if it exists. That is where I customarily define aliases, and it looks to me as though a bad alias may be your problem.
I'm not saying it was the one you made, although it might be. Just go through your rc and profile files and look for any aliases which might in any way clash with source.
I suspect the source command is working just fine and the problem is a bad line in the ~/.bash_profile itself that looks like it's trying to run a command named s. I would look in there for the problem.
It might help to run it with xtrace on via bash -x ~/.bash_profile – running it in a separate process like that won't have any of the presumably-desired side effects of sourceing it in your current shell, but you can see what it's trying to do so that you can fix it.
(You can also just set -x before the source and get both xtrace and running in the current shell; just be sure to set +x afterwards or your shell session will be full of debug output.)

conda init not initialising new shell

I have tried many times to initialise conda for shell interaction using the command "conda init bash" on my terminal but it always says "No action taken."
What am I doing wrong?
With so little details in your question it's hard to help you. You should read carefully and paste what conda init bash is outputting (and your .bashrc, .bash_profile and output of PATH).
I was in a similar issue and what happened was that the conda init modifies your .bash_profile and adds some code at the end. But if you are running your .bashrc before that code is being added then conda won't behave correctly during the loading of your bashrc file. So inspect both files and make sure they are the way you expect them (especially because code analysis is undecidable).
Also, make sure your PATH environment variable looks the way you expect. If not make sure your not modifying it in unexpected ways and that the path to conda is there correctly.
See my answer here for more details: Why is conda init updating my .bash_profile incorrectly?
Additionally, if you are using vscode you might have other problems like needing to set the terminal.integrated.inheritEnv to false. Read here for more info: https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments
Opening and closing vscode completely seems to help a lot, do this.
Another helpful tip is to go the top left of vscode where it says code click it then go to preferences and then settings. Then you can change the terminal.integrated.inheritEnv to false by unclicking/selecting it.

Bash issue when open terminal [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 2 years ago.
I receive this error message each time I launch terminal:
-bash: =/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: No such file or directory
You have recently edited one of your shell's startup files and introduced an error.
Probably, ls -lart ~/.bashrc ~/.bash_profile ~/.profile will indicate which one -- if one or more is missing, that's no concern, we just want to see which one out of these you have edited recently. Examine the time stamps and try to remember what you did to change one of these files.
The error probably looks something like
$oopsPATH=/usr/local/bin:$PATH
where you meant to say
PATH=/usr/local/bin:$PATH
but without access to your files, we can't know what exactly is supposed to be there, or how you messed it up.
See also https://askubuntu.com/questions/198730/how-to-restore-bashrc-file/198740#198740
In the common case where you have messed up your PATH so that ls and other commands are unavailable (bash: ls: command not found), you can use the full path (/bin/ls pro ls, etc; though obviously, you have to know the correct path) at least until you can restore your configuration.
PATH=/usr/local/bin:/usr/bin:/bin
is probably a good crutch until you can find the correct default for your OS. You can type that at the prompt, or put it in one of your shell's startup files and start a new shell.
On many platforms, you can find the default user dot files in /etc/skel so if that's present (which unfortunately will not be true for Mac OS, but should be there on most Linuxes):
cp -b /etc/skel/.bash_profile $HOME/
will replace your (presumably broken beyond repair) .bash_profile with the system default one. (Omit the -b option if your OS doesn't have it, but then you'll want to back up your file manually before replacing it.)
Update: This fragment near the top of your .bash_profile is erroneous:
#loginPath
=/usr/local/bin:$PATH
Just take it out; it doesn't seem to do anything useful. There seem to be multiple additional fragments from the MacPorts installer which look wrong, too, but they are just comments. (Perhaps somehow they shouldn't be?)
It seems that you are missing a necessary PATH and that is why it is saying no such file or directory. If, for example, you get this error message when typing in python, it would mean either that (1) python isn't installed; or (2) python isn't on your system path.

Error message on Terminal launch [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 2 years ago.
I receive this error message each time I launch terminal:
-bash: =/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: No such file or directory
You have recently edited one of your shell's startup files and introduced an error.
Probably, ls -lart ~/.bashrc ~/.bash_profile ~/.profile will indicate which one -- if one or more is missing, that's no concern, we just want to see which one out of these you have edited recently. Examine the time stamps and try to remember what you did to change one of these files.
The error probably looks something like
$oopsPATH=/usr/local/bin:$PATH
where you meant to say
PATH=/usr/local/bin:$PATH
but without access to your files, we can't know what exactly is supposed to be there, or how you messed it up.
See also https://askubuntu.com/questions/198730/how-to-restore-bashrc-file/198740#198740
In the common case where you have messed up your PATH so that ls and other commands are unavailable (bash: ls: command not found), you can use the full path (/bin/ls pro ls, etc; though obviously, you have to know the correct path) at least until you can restore your configuration.
PATH=/usr/local/bin:/usr/bin:/bin
is probably a good crutch until you can find the correct default for your OS. You can type that at the prompt, or put it in one of your shell's startup files and start a new shell.
On many platforms, you can find the default user dot files in /etc/skel so if that's present (which unfortunately will not be true for Mac OS, but should be there on most Linuxes):
cp -b /etc/skel/.bash_profile $HOME/
will replace your (presumably broken beyond repair) .bash_profile with the system default one. (Omit the -b option if your OS doesn't have it, but then you'll want to back up your file manually before replacing it.)
Update: This fragment near the top of your .bash_profile is erroneous:
#loginPath
=/usr/local/bin:$PATH
Just take it out; it doesn't seem to do anything useful. There seem to be multiple additional fragments from the MacPorts installer which look wrong, too, but they are just comments. (Perhaps somehow they shouldn't be?)
It seems that you are missing a necessary PATH and that is why it is saying no such file or directory. If, for example, you get this error message when typing in python, it would mean either that (1) python isn't installed; or (2) python isn't on your system path.

Resources