bash conda autocomplete on macos - bash

I would like to enable auto complete for conda commands when I press tab.
I have searched the internet and find some documentation. I have applied the proposed solution, but auto complete is still not working.
conda.io: enable-tab-completion
Is there any other approach. How could I enable autocomplete for conda commands?

Autocompletion is now possible with conda-bash-completion. Just install it by entering the following in your terminal:
conda install -c conda-forge conda-bash-completion
The developer provides more thorough instructions on the project's github page.

Autocompletion for conda is not supported in bash right now.
Conda versions up to 4.3 supports tab completion in bash shells via
the argcomplete package. Tab completion is deprecated starting with
version 4.4. See issue #415.
It will technically work with versions prior to 4.4, but I will not recommend using versions so old as major changes were introduced since then, and the development pace of conda is quite fast.
Three possible solutions:
this issue states completion works for Fish shell, so you might use fish
the same issue suggests someone could implement autocompletion for Bash... if you're looking for a project contributing to conda. I believe the conda team will gladly point you to the right direction for this.
there is mention of a hack for Bash, although this is a few months old with no guarantee it will work, and could break at any time

To enable tab completion:
Make sure that argcomplete is installed:
conda install argcomplete
Add the following code to your bash profile:
eval "$(register-python-argcomplete conda)"
Test it:
Open a new terminal window or an Anaconda Prompt.
Type: conda ins, and then press the Tab key.
The command completes to:
conda install
Source:
https://conda.io/projects/conda/en/latest/user-guide/configuration/enable-tab-completion.html

Related

Mas OS Big Sur update - Python3 / conda / pip not found

Sorry if this is a stupid question. I use python/jupyter a lot and it's stopped working after updating from Mac OS High Sierra to Big Sur. I'm trying to figure out why, but I'm not great with command line stuff.
The problem. When I try python3, pip -v, conda, etc. it says "command not found". python still seems to run, but it's 2.7 and I know I had 3 (I probably had a few versions from untidy file systems). I want to avoid reinstalling all my packages and things again, because I know it's still there and I've done this a few times already.
Some clues. I know this OS upgrade moves me from bash to zsh. I've tried just switching back to bash with chsh -s /bin/zsh but it still says command not found. I also noticed the OS update creates a Mac HD (below System/Volumes) within my Mac HD, and in that second one seems to be still all my python3/conda/pip/etc. folders. Not sure if/how this matters. Or if this is just a path issue.
I just want to get Jupyter running again on my Mac without reinstalling all my myriad packages from square one. Any help appreciated!
After extreme toil and research, I finally found something that worked for me.
Find the location of your Anaconda3. For me it was in ~/opt/anaconda3
Open terminal and type source <location of anaconda3>/bin/activate and then in the next line, write conda init zsh
Close your terminal and open it again. You should see a prefix (base) when you open it again.
All in all, for me it was
rko3 ~ % source opt/anaconda3/bin/activate
rko3 ~ % conda init zsh
Let me know if this works for you!
PS. You may be tempted to change $PATH variables. Anaconda advises against that. Use this reference instead that suggests the above. https://docs.anaconda.com/anaconda/install/mac-os/
I've just resolved this exact issue on my machine after upgrading to Big Sur from Mojave.
The issue: MacOS, as of Catalina, no longer lets you use the system root folder. Anaconda used to install in this folder. After upgrading from Mojave to Big Sur, you'll likely find your anaconda3 folder, including all your environments and packages, located here: /System/Volumes/Data/anaconda3.
Here is what to do to fix it:
Open Terminal
Move the anaconda3 folder:
sudo mv /System/Volumes/Data/anaconda3 ~/
Download Anaconda's Conda Prefix Replacement (crp) tool:
curl -L https://repo.anaconda.com/pkgs/misc/cpr-exec/cpr-0.1.1-osx-64.exe -o cpr && chmod +x cpr
Run the CRP tool (this will take a few minutes):
./cpr rehome ~/anaconda3/
Source anacoda3
source ~/anaconda3/bin/activate
Initiate conda
conda init
Quit Terminal and open it again.
Edit: Someone didn't like that I ended this answer with "That's it! Enjoy". In the scenario described, the steps above were indeed all it took to resolve the issue. If you're experiencing the same issue, I hope this helps resolve it, so you can get back to enjoying your updated OS.
Seems like your environement is not activated. Zsh sources ~/.zshrc while bash sources ~/.bashrc.
You can copy lines related to conda from your ~/.bashrc to your ~/.zshrc.
AF
Open the Anaconda navigator and click on the Environments section. There you will see the base (root) and a green triangle next to it.
Click on the triangle and select Open Terminal.
Now, in the terminal you will be already in the necessary directory for anaconda and you can then update any packages.
For example, just by writing conda update --all you can update all packages available for updates.

Conda hangs in "solving environment" when installing STSci packages

I run Ubuntu 18.04.1 LTS on a virtual machine on Windows 10. I've installed Anaconda 5.3 without any issues, but when I try to install an STSCI environment with the command line:
conda create -n astroconda stsci
the terminal gets stuck in "Solving Environment" (I have version 4.5.11 of conda). Yesterday I waited for about 4 hours before giving up. I would like to know if there is a known issue about this problem and if it can be related to the quantity of disk and RAM assigned to the virtual machine.
I will write a more general solution, to Conda's "Solving Environment" issue, which I had the uttermost pleasure with.
Short answer of things to try:
As already mentioned try updating Conda with conda update conda or even better, the whole base environment conda update --all.
Specify package and build version using <package>=<version>=<build> e.g. sage=8.3=py27_3. Search available versions by conda search <package>.
Like for the package, you can also specify python version and ideally some other dependencies. Check dependencies with conda info <package>.
Check current configuration inside the .condarc file or with conda config --get and check if you maybe have additional restrictions, as normally you will only find the channels defined there.
When working with additional channels put conda-forge or the channel you want to use on top and add channel_priority: strict. So your .condarc file would look like this:
channel_priority: strict
channels:
- conda-forge
- defaults
Contrariwise to the above, remove the first line and try adding --no-channel-priority to the command. This one helped me a couple times since updating to Conda 4.6.
If above does not work:
When conda seem stuck it is possibly having too many options or some conflicts resulting in the SAT solver getting clause counts of multiple millions.
To check if this is the case add -vv or --debug and you will later see lines like Invoking SAT with clause count: XXX. If it stays at one of these lines for long time, then try specifying version for packages as above. If there seem another issue, try the conda GitHub.
Another useful tip if you are using the conda-forge channel, is to go over their Tips & tricks.
I have the same problem on macOS 10.13.6.
The creation of iraf environment
conda create -n iraf27 python=2.7 iraf-all pyraf-all stsci
works fine instead.
Update: I found out that specifying the python version
conda create -n astroconda python=3.6 stsci
makes the installer work also with astroconda.
I had the same issue but then I updated Conda and it worked...
$ conda update conda

How to enable auto-completion with Git [all platforms]

How to enable auto-completion with Git?
When using Git on different platforms, auto-completion is not always enabled/available.
Note that this question is NOT a duplicate of git auto-complete for branches on the command line, because that question was only about Apple users. This question is mostly the same, but including other platforms too.
You need to get bash's programmable completion configured to return the possible commands. You can see the "Programmable Completion" section in the bash man page if you want to implement it yourself.
A much easier method to use a script to pre-configure bash's programmable completion. On most distributions, the file for git completion, /etc/bash_completion.d/git (on Fedora and derivatives), /usr/share/bash-completion/completions/git (on Debian and derivatives) (other distributions might have it in other places, try locate or find to locate it) are provided by the git package. (If it is not included with your git package, you can get it from here).
You can configure bash to source the file when it is started (probably using .bashrc), or you can install bash-completion, which will automatically load completions like the one that the git package installs (and generally completions from /etc/bash_completion.d/ or /usr/local/etc/bash_completion.d/ (typically BSDs)). On most distributions, bash-completion should be available in the repositories and you can simply install the package. For other systems, see the instructions included in the README.md to install it. (On non-GNU/Linux systems, some completions might need to be disabled to prevent it from outputting errors when starting)
Apple users
See question git auto-complete in the command line
Linux users
Solution tested with Debian 9 (Stretch)
sudo apt install bash-completion
Pros:
Very easy for newcomers to Linux/scripts
No "manual" downloading
Only makes use of the official repos: the "safest" way.
Easy to update: sudo apt update then sudo apt upgrade
I also know that the question was asked for Apple users, but it shows up first in Google for "git auto-completion branch", so I thought a Linux answer would still be useful.

bash __git_ps1 command not found

I am a beginner trying to setup a developer environment on my new Mac following the steps from this link: http://vanderveer.be/setting-up-my-perfect-developer-environment-on-osx-10-8-mountain-lion-10-8-2-final-edition/.
After executing the files from git, my terminal window now shows:
rbenv: version `1.9.3-p194' not installed
-bash: __git_ps1: command not found
The first line only shows when I open a new terminal window, while the second shows everytime I press return no matter what I type into the terminal.
I have read through many questions on stackoverflow and tried to mimic their solutions to no avail. I think I've made a mistake in installing the package from git as I am not so experienced and I think now I may have messed up the configurations, and was also wondering if there is any way to go back to default settings for bash?
Many thanks!
Allen
If you've not installed a newer version of Git on your Mac, start by doing that. You can grab the download from here: http://git-scm.com/download
Once it's installed, you should source git-completion.sh and git-prompt.sh from your ~/.profile (or ~/.bashrc, if you have it):
source /usr/local/git/contrib/completion/git-completion.bash
source /usr/local/git/contrib/completion/git-prompt.sh
That should fix the __git_ps1 error.
I'm not a Rubyist, but the rbenv error is coming from the fact that the setup in the dotfiles you are following is trying to set the default Ruby version to "1.9.3-p194". The rbenv tool is there to make a number of different Ruby versions available, but you have to install them first. In your case, I think you need to run this:
rbenv install 1.9.3-p194
After that, the version will be available, and you shouldn't see the warning anymore.

Install Git separately from Xcode

Firstly apologies if this is a really simple question but Git is absolutely brand new to me. Basically I've been dabbling with a bit of iOS development for a little while and now have a project idea that I want to start working on and for the first time I'm planning on putting this into source control.
Now I know Xcode 4 has some Git integration but I've spotted a couple of posts that suggest the integration isn't that great and it's better to do it the command line way.
So, I've been following instructions here http://git-scm.com/book/en/Getting-Started-Installing-Git and I've downloaded version 1.7.10.3 for Mac and ran the install.
However when I run git --version I get version 1.7.4.4 which is the version that was installed with Xcode I assume?
My question is, how do I make use of my new version 1.7.10.3? The plan is to learn to use Git via command tools and set up a central repository on a server I have at home, then have local copies on my laptop.
As I say I'm really new to this, so a quick step by step idiots guide would be helpful. I have searched and tried to find details here and on google but other than the suggestion to use Git outside of Xcode I've not found out exactly how to do it.
Any advice, or links to a decent tutorial that covers this would be very much appreciated.
Update:
I've changed the path to the new path in .bash_profile (/usr/local/git/bin) and now get git version 1.7.7.5 (Apple Git-26). This still appears to be the wrong version (although this could be me being dense). I downloaded the installer for OSX from the above link. Should I be doing something else. I want to play around with the command line tools so I can get a proper understanding
Update 2:
I'm now also trying MacPorts as recommended in the article. This seems to be downloading a lot more than just Git though
Xcode installs git in /Applications/Xcode.app/... but if you run 'Install Command Tools' then git gets installed also in /usr/bin/git. Xcode uses its private version in Xcode.app. If you installed git in /usr/local/git/bin then you need to include that directory in your PATH. You should have a .bashrc file (or equivalent for whatever shell you are using). Add
PATH=/usr/local/git/bin:$PATH # your shell might use different syntax.
to that file 'rc' file.
Also, note that Xcode would allow you to accomplish your goal of setting up a remote at home while maintaining a local copy on your laptop. Go to the Xcode 'organizer' and click 'repositories'. There you will find all your machine's Git repositories. Choose one, select the 'remotes' folder and then '+' to add your home remote. I use Xcode this way.
Credits goes to #GoZoner for the answer. I'm just summing up everything.
Download official git installer from : http://git-scm.com/download/mac
Install and add its directory to your path :
echo "PATH=/usr/local/git/bin:\$PATH" >> ~/.bash_profile
source ~/.bash_profile
The best way is:
step 1:
Install homebrew on your mac this is the official website Homebrew homepage
From a Terminal prompt:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
step 2:
From a terminal prompt
brew install git

Resources