I tried adding autocomplete using shtab but it doesn't work :(
The completion file (/etc/bash_completion.d/shtab) looks ok, but hitting TAB does nothing
Reproduce:
virtualenv -p python3.6 venv && . venv/bin/activate
pip install -U shtab
shtab --shell=bash shtab.main.get_main_parser --error-unimportable | sudo tee /etc/bash_completion.d/shtab
I changed the "$BASH_COMPLETION_COMPAT_DIR"/shtab into /etc/bash_completion.d/shtab because it is not relevant anymore (though I did also run the original command)
My environment:
Ubuntu 18.04
Python3.6
shtab==1.5.2
Bash 4.4.20
Tried also on:
zsh==5.4.2
Docker (docker run -it python /bin/bash)
Is there an issue with my environment?
It may be that you are trying to complete something where there is nothing to complete. For example, shtab <TAB> will do nothing since it has no subcommands. The same is true for cp <TAB>, grep <TAB>, etc.
Meanwhile, shtab -<TAB> (and cp -<TAB>, grep -<TAB>, etc.) will happily complete the supported option flags. This comment may help: shtab#45#901736610.
Related
Here I'm going to use flake8 within a docker container. I installed flake8 using the following command and everything installed successfully.
$ sudo -H pip3 install flake8 // worked fine
and it's location path is-
/usr/local/lib/python3.8/dist-packages
Then I executed the following command but result was not expected.
$ sudo docker-compose run --rm app sh -c "flake8"
It says,
sh: flake8: not found
May be, the flake8 package is not installed in the correct location path. Please help me with this issue.
When you docker-compose run a container, it is in a new container in a new isolated filesystem. If you ran pip install in a debugging shell in another container, it won't be visible there.
As a general rule, never install software into a running container, unless it's for very short-term debugging. This will get lost as soon as the container exits, and it's very routine to destroy and recreate containers.
If you do need a tool like this, you should install it in your Dockerfile instead:
FROM python:3.10
...
RUN pip3 install flake8
However, for purely developer-oriented tools like linters, it may be better to not install them in Docker at all. A Docker image contains a fixed copy of your application code and is intended to be totally separate from anything on your host system. You can do day-to-day development, including unit testing and style checking, in a non-Docker virtual environment, and use docker-compose up --build to get a container-based integration-test setup.
I am new to shell scripting and what I basically want is to write a script that installs all the software needed for my project to work on a Windows machine without asking the user any additional input aside from running the script itself.
For instance, I want to check if python3 and conda are installed and if not install them without asking the user for additional input.
For conda I was able to figure out the next couple of lines:
if ! command -v conda &> /dev/null
then
echo "conda could not be found"
echo "installing conda..."
MINICONDA_INSTALLER_SCRIPT=Miniconda3-latest-Windows-x86_64.exe
curl --location -C - --output "$MINICONDA_INSTALLER_SCRIPT" "https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT"
start /wait "" ./$MINICONDA_INSTALLER_SCRIPT /InstallationType=JustMe /RegisterPython=0 /S /C=%UserProfile%\Miniconda3
fi
The code above does not work completely, but I am sure I will be able to figure it out. It is just proof of concept.
I want to have something similar for python3 as well. That is, the script should download and install python3 in silent mode with default settings. On Linux I would just use something amount the lines:
sudo apt-get install python3
but on Windows, I don't know how to do that. Is there a way to do that in the first place?
I am trying to build a docker from a base image, the Dockerfile is like this:
FROM my/base/image:latest
RUN conda install package-name
RUN rm -rf /tmp/*
CMD ["/bin/bash"]
and I got "conda: command not found". But if I directly run the base image as a container, the conda command works fine.
Also, if I add RUN source ~/.bashrc in the Dockerfile, when building process run into this line, it will enter another terminal and will not response to any command. What‘s happening in this situation? I would be very grateful if anyone could give me any advice and suggestion. Thanks in advance.
~/.bashrc is sourced by interactive shells, it's the reason why it works when you use it from within the container. This is not the case for a Dockerfile during the build process.
In the conda docker image, the conda executable is simply added to the PATH.
ENV PATH /opt/conda/bin:$PATH
It's a simple solution. You can also call /opt/conda/bin/conda install ... (to adapt according to your conda installation) if you do not want to alter the PATH.
Alternative
If you want to have ~/.bashrc sourced you can use the SHELL instruction to override the default shell used for commands with a bash interactive shell (thanks to the i flag).
SHELL ["/bin/bash", "-i", "-c"]
RUN conda install ...
However it seems to be a less conventional approach.
my anaconda (4.5.4) works fine as long as I just use it via a linux terminal (bash shell). However, running conda commands in a bash script does not work at all.
The script test.sh containes these lines:
#!/bin/bash
conda --version
conda activate env
Now, running bash test.sh results in the error
test.sh: line 2: conda: command not found
test.sh: line 3: conda: command not found
As recommended for anaconda version > 4.4 my .bashrc does not contain
export PATH="/opt/anaconda/bin:$PATH",
but
. /opt/anaconda/etc/profile.d/conda.sh
Thank you.
I solved the problem thanks to #darthbith 's comment.
Since conda is a bash function and bash functions can not be propagated to independent shells (e.g. opened by executing a bash script), one has to add the line
source /opt/anaconda/etc/profile.d/conda.sh
to the bash script before calling conda commands. Otherwise bash will not know about conda.
If #randomwalker's method doesn't work for you, which it won't any time your script is run in a more basic shell such as sh, then you have two options.
Add this to your script: eval $(conda shell.bash hook)
Call your script with: bash -i <scriptname> so that it runs in your interactive environment.
Let's say you try to access user name with "miky" # "server" address.First when you login to your user ; learn conda path with "which conda" then probably you will get a path such as "/home/miky/anaconda3/bin/conda"
then put your conda commands as follow (in my example i use conda to install a mysql plugin forexample.): shh miky#server -t "/home/miky/anaconda3/bin/conda install -y -c anaconda mysql-connector-python" thats all.
do sudo ln -s /home/<user>/miniconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh and try again. This should activate conda for all users permenantly
source
I would like to install Anaconda on a remote server.
The server is running Ubuntu 12.04.
I only have access to this server via SSH.
How can I install Anaconda via the command line?
Something along the lines of:
wget https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
to get the installer for 64 bit linux followed by:
bash Anaconda3-2020.07-Linux-x86_64.sh
You can get the latest release from here
Please take a look at the Anaconda repo archive page and select an appropriate version that you'd like to install.
After that, just do:
# replace this `Anaconda3-version.num-Linux-x86_64.sh` with your choice
~$ wget -c https://repo.continuum.io/archive/Anaconda3-vers.num-Linux-x86_64.sh
~$ bash Anaconda3-version.num-Linux-x86_64.sh
Concrete Example:
As of this writing, Anaconda3-2020.07 is the latest version. So,
~$ wget -c https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
~$ bash Anaconda3-2020.07-Linux-x86_64.sh
P.S. Based on comments, this should also work in CentOS systems.
You can do as Prashant said or you can use bash scripts to automate the installation. Just simply copy and paste depending on the version of Python you want
If you are trying to it entirely in command line you use a bash script
python 2 anaconda install bash script:
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh
bash Anaconda2-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda2-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc
# Refresh basically
source .bashrc
conda update conda
python 3 anaconda install bash script
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh
bash Anaconda3-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda3-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc
# Refresh basically
source .bashrc
conda update conda
Source: https://medium.com/#GalarnykMichael/install-python-on-ubuntu-anaconda-65623042cb5a
Download Anaconda for linux, place in your ubuntu system through WinScp, then
$ sudo bash Anaconda2-4.3.0-Linux-x86_64.sh
after this logout of your ssh session and then login, you will get base environment.
1 - Go to Anaconda Repository, find the installation for your OS and copy the address
2 - wget {paste}. Ex: https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
3 - Execute with: bash. Ex: bash Anaconda3-5.2.0-Linux-x86_64.sh
Run!
$ sudo bash Anaconda2-4.3.0-Linux-x86_64.sh
Video tutorial::
https://youtu.be/JP60kTsVJ8E
Just download the anaconda installer and execute it as it is a shell script. Follow the steps :
In the terminal type "wget https://repo.continuum.io/archive/Anaconda-2.3.0-Linux-x86_64.sh"
The file will be downloaded in current directory. Now execute the downloaded file by "bash ./Anaconda-2.3.0-Linux-x86_64.sh"
Restart the terminal. This is very important for python version provided by anaconda to be set to default for that user.
Note- Try using environment for using different version of python. Changing the default python version for root might result in non functioning of some functionalities like yum.