How to activate a conda env automatically in VSC on windows using bash? - bash

I've been trying all day to debug a code using Visual Studio Code without success. I have installed VSC on windows and I have installed bash (ubuntu) as well. I already put bash as a terminal default shell:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
The thing is when I run the debug, it tries to activate the env with activate myenv-name and I couldn't find how to change this instruction to source activate myenv-name.
Do you know how I can do this? any help will be appreciated. Thanks!

It's been a while since I asked this question and I got the answer finally. :)
It is simple we just have to create .bashrc file in our user folder there we can write whatever commands we need to run each time we start a terminal in vscode.
Here the command to activate a conda env:
source activate myenv_name
In case of bash: conda: command not found and you don't have admin permissions to change the paths use this command before source act...:
export PATH=$"/c/Users/UserName/AnacondaPath/Scripts":$PATH

Related

Miniconda: issue with shell configuration/initialization

I installed miniconda on our CentOS cluster and it all went fine. Then I asked miniconda to create a python 3.8 environment, and it went fine. However, when I try to activate the environment, I get the following error:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
I verified, and it's a bash environment. So I ran conda init bash and I got the following outputs:
no change /MyPath/miniconda3/condabin/conda
no change /MyPath/miniconda3/bin/conda
no change /MyPath/miniconda3/bin/conda-env
no change /MyPath/miniconda3/bin/activate
no change /MyPath/miniconda3/bin/deactivate
no change /MyPath/miniconda3/etc/profile.d/conda.sh
no change /MyPath/miniconda3/etc/fish/conf.d/conda.fish
no change /MyPath/miniconda3/shell/condabin/Conda.psm1
no change /MyPath/miniconda3/shell/condabin/conda-hook.ps1
no change /MyPath/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change /MyPath/miniconda3/etc/profile.d/conda.csh
no change /home/users/me/.bashrc
No action taken.
So nothing happens. And when I try to activate the new environment, then I still get the first error.
Any idea how I can fix this?
[Solution] Thanks to the answer below, the issue was that despite testing that I was running/using a bash, I still have to run "bash" in the command line before activating model.
have you tried manually adding to ~/.bashrc?
add export PATH="/home/username/miniconda/bin:$PATH" in your bashrc file. make sure to replace /home/username/miniconda with your actual path now save the file, quit and reopen the terminal should work I guess.

Why did my terminal suddenly has darwin13 as host? How do I fix this?

I was trying to install Kaggle but then all of a u sudden I see:
#x86_64-apple-darwin13 on my terminal.
How do I switch this back? I was trying some solutions I found online but every time I run open ~.bash_profile it says:
zsh: no such user or named directory: .bash_profile
Every time turn on terminal, conda will be activated automatically.
Try the following command should work
conda config --set auto_activate_base false

Why is git bash behaving weird on PyCharm?

I am using PyCharm 2019.3.3 (Community Edition) on Windows 8. I wanted to integrate Git bash in the PyCharm terminal. I have set the shell path in the terminal application settings of PyCharm as
C:\Program Files\Git\bin\bash.exe
The problem occurs when I activate a venv virtual ennvironment, set up using
python -m venv env
by running
source env/Scripts/activate
I think env is active as I see two parenthesis, () and typing pip freeze displays all installed packages in env. But this is accompanied with an error message that displays in the terminal
bash: basename: command not found
This same message is logged after typing commands like ls, clear which doesn't work but pip freeze and pip --version work. And when I deactivate env, ls, clear and pip stopped working displaying the mentioned error message.
All this problems do not occur in the Git bash application for Windows irrespective of whether I am in env or global environment and all commands work properly. I know I can just use Git bash instead of the integrated terminal of PyCharm but just wanted an answer to this problem.
What seems to be the problem here? Am I setting up my shell path wrongly or is this problem specific to PyCharm?
I solved this issue by disabling "Activate Virtualenv" checkbox in File -> Settings -> Tools -> Terminal
Since, pycharm documents does not show any support for 'Git Bash', that is probably the reason for this weird behaviour.
Terminal Options in Pycharm

"code ." command is not working

I get this error:
code . is not recognised as an external or internal command, operable program or batch file
moreover shell commands are not coming in my compiler VS code neither do setx path "%path%;C:\Program Files\Microsoft VS Code" is working in command prompt .
It looks as if you do not have the code program installed. You can open the Command Palette,
Mac: ShiftCmdP
Windows/Linux: ShiftCtrlP
And search "install command", which should return this as one of the options:
Shell Command: Install 'code' command in PATH
Run that, and it should install the code command, after which you should be able to use it.
For Mac OS,
You can paste this into your terminal, or in your .bashrc file (or whatever shell config file you are using) :
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
I found it. In the "search" type environment variables then click on the "edit system environment variables".
Inside Environment variables->Path put C:\Users\{your_username}\AppData\Local\Programs\Microsoft VS Code\bin.
Go to the project folder and open the cmd with it typing in the location bar and then type code .
That will do.
in windows problem is with insiders version of VSC.
You can use 'code-insiders .' command or make a copy of 'code-insiders.cmd' file as 'code.cmd' inside folder with code-insider (use 'path' command to see where your VSC is installed)
make sure you run the command in C folder
Then click window key + R and type rundll32.exe sysdm.cpl,EditEnvironmentVariables
then enter .
It will open Environment Variables edit Path variable .
Check whether you have C:\Users\{pc name}\AppData\Local\Programs\Microsoft VS Code\bin if not add it and run code -v in C folder cmd
This worked for me !
For Windows OS
For Windows, you'll need to re-install code. You can download the latest version and just install it overtop of your existing install.
During setup, make sure to check the box to Add to PATH
See Also: The VSCode docs on installing the CLI
After installation, you need to restart your computer to make the PATH changes effective. Post restart, the command worked for me.
about linux, if u can't see the >shell option with ctrl+shif+p, You could install via
sudo snap install --classic code
and try again
code .

Configuring bash environment variables in VSCode

So far I've nearly got the setup I want for using GIT (Windows). All works fine from Git bash with SSH, Passphrases, the SSH config file and SSH-Agent.
But I can only communicate with any remote Repo's if I start Visual Studio from GitBash terminal by running "code"
This will be because the environment from the bash terminal is passed on to VSCode. I'm thinking I can get VSCode to do this without having to initiate it from the GitBash terminal if I can get the SSH-AGENT environment variables added to the VSCode environment somehow.
i.e. SSH_AUTH_SOCK and SSH_AGENT_PID.
Could there be a way to set these environment variables on startup of Code? This is assuming the SSH-Agent is already running with pre-defined values for those two variables. It's there, I just need to tell Code where to find it.
I've configured most of my setup as per:
http://letsdosql.blogspot.co.uk/2018/04/accessing-git-part-2-ssh.html
And with the ssh .config file:
https://developer.atlassian.com/blog/2016/04/different-ssh-keys-multiple-bitbucket-accounts/
Thanks in advance!
Ok. So the purpose of this was to open VSCode while being able to make use of SSH-Agent... without having to manually open up GitBash and start code from there. So all I've done is create a shortcut to a .sh script file which simply has "code" in it.
If I call the script via sh.exe, it still leaves a terminal window open while just referring to a .sh file directly does not. Also, now sessions of Code can access the SSH-Agent.
The only downside is if I start VCSode from a context menu it doesn't, but this works for me for now.

Resources