Issue with Anaconda installation - linux

I had previously installed ananconda and it was working fine but suddenly the Ubuntu gives busy box error so I had to run manual fsck command after starting the Anaconda stopped working.
ananconda -command not found.
I checked the bashrc file the PATH exported is anaconda3/bin but when I run echo $PATH it gives anaconda3/condabin. How do I resolve it.
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

You also have to remove the anaconda3/condabin from the $PATH variable.
export PATH=${PATH%:/home/YOUR_USER/anaconda3/condabin}

Related

Anaconda M1 Mac Install Issues

I installed Python through Anaconda's 64-bit Graphical Installer Python 3.8 but when I checked the version it shows 2.7, any advice?
The below commands also does not work when I try to uninstall/remove anaconda:
rm -rf ~/anaconda3
conda install anaconda-clean ーー> (Error msg : zsh: command not found: conda)
anaconda-clean
anaconda-clean --yes
I tried using the command line installer and it doesn't work either.
Is there any way to safely remove Anaconda and the Anaconda Navigator?
Try typing python3 instead of just python.
Make sure that you're shell (bash / zsh) is initializing anaconda.
If you're using zsh, run cat ~/.zshrc and check for a script that looks like this:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/<username>/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/<username>/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/<username>/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/<username>/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
If you're using bash, run cat ~/.bash_profile, but the script should be the same.
If it's not there, you may have missed something during installation. I would recommend just downloading the shell script (cli) installer and running again.
Ultimately, if that conda initialization script has executed successfully, you should see (base) before in your terminal.

Python virtual environment not activating from bash script

Now before you mark this as a duplicate, I have tried the solution posted here and they aren't working for me. I tried making an alias and I tried creating a function as so:
activate () {
echo Activating Virtual Environment...
source alexa/bin/activate
}
activate
But my script just gets run through without a virtual environment getting activated. The script is being run from the same directory as my virtual environment directory, alexa.
For clarity, the other solution I tried was to make an alias:
alias activate="source alexa/bin/activate"
activate
That didn't work and gave me an error that ./alexaEnvSetup.sh: line 43: activate: command not found.
Any thoughts or ideas?
EDIT: I think it is worth mentioning that the echo command does print out when I do this. So the function is getting entered. The virtual environment is just not getting activated.
EDIT: Adding full code:
#!/bin/bash
if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo Operating system: Linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo Operating system: Mac OSX
echo
# Install Python 3.6.5 using `curl`
curl -O https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar xf Python-3.6.5.tgz
cd Python-3.6.5
./configure
make
make install
echo
echo Python Version 3.6.5 Installed
echo
# Install Pip
curl -O http://bootstrap.pypa.io/get-pip.py
/usr/local/bin/python3.6 get-pip.py
echo
echo Pip Installed
echo
# Install virtualenv
pip install virtualenv
echo
echo Virtual Environment Installed
virtualenv -p python3 alexa
echo Created Virtual Environment, \"alexa\"
activate () {
echo Activating Virtual Environment...
source /Users/XXXX/Auto-Lab/Commerce/alexa/bin/activate
}
export -f activate
activate
echo Virtual Environment, \"alexa\", Created and Activated
echo
# All packages (time, urllib, and json) should come default with Python3
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
echo Operating system: Cygwin
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
echo Operating system: Msys
elif [[ "$OSTYPE" == "win32" ]]; then
echo Operating system: Windows32
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo Operating system: FreeBSD
else
echo Operating system unknown.
fi
use the full path to the activate script in the function: source /path/to/activate
export the function: export -f activate
ensure the script is a bash script: #!/bin/bash
The following works for me using Anaconda virtual env, perhaps it will work with yours also?
#!/usr/bin/env bash
# do bash stuff
# Python env
PATH=/home/username/path/to/activate/bin
python -u /script/to/run

Installing and running .sh file in linux mint

I'm using Linux mint and I want to install COMSOL. The problem is that, when I run below code in terminal, there is an error which doesn't make sense. Could anyone solve the problem?
The code I wrote:
./COMSOL_Server_Workaround.sh
the error is:
COMSOL Server Installer Work-around Script
2016 TeAM SolidSQUAD-SSQ
./COMSOL_Server_Workaround.sh: 14: [: Linux: unexpected operator
./COMSOL_Server_Workaround.sh: 15: [: Linux: unexpected operator
-e ERROR: This script should be executed
from the COMSOL Server installation directory
(where comsolsetup.log resides)
picture of files
COMSOL_Server_Workaround.sh contains:
#!/bin/sh
echo
echo COMSOL Server Installer Work-around Script
echo 2016 TeAM SolidSQUAD-SSQ
echo
# assume working dir is COMSOL installation root
COMSOLROOT="$PWD"
# check architecture
[ "`uname`" == "Linux" ] && COMSOL_TARS="fl fl_setup_glnxa64 fl_setup_maclnx fl_jvm_glnxa64 fl_glnxa64 mph_maclnx mph_glnxa64"
[ "`uname`" == "Darwin" ] && COMSOL_TARS="fl fl_setup_maclnx fl_maclnx fl_jvm_maci64 fl_maci64 mph_maclnx mph_maci64"
# tell user he has to run the script from COMSOL Server folder
[ ! -e "$COMSOLROOT/comsolsetup.log" ] && echo -e "ERROR: This script should be executed\n from the COMSOL Server installation directory\n (where comsolsetup.log resides)" && exit 1
# check if we can write to folder
[ ! -w "$COMSOLROOT/comsolsetup.log" ] && echo -e "ERROR: Cannot write to folder \"$COMSOLROOT\".\n If COMSOL Server was installed as root, run this script as root too\n otherwise run it as user which made the installation of COMSOL Server!" && exit 2
# let us extract the source location and check if it accessible
COMSOLDVD="`grep "^cs.installroot" "$COMSOLROOT/comsolsetup.log" | awk '{print $3}'`"
echo "COMSOL SERVER Installation Path = $COMSOLROOT"
echo "COMSOL Server Installation Source Path = $COMSOLDVD"
# check if source is accessible
[ ! -r "$COMSOLDVD/setupconfig.ini" ] && echo "The installaton source \"$COMSOLDVD\" id not accessible! Make sure the DVD is mounted" && exit 3
# now start untaring FL archives
for COMSOL_TAR in $COMSOL_TARS
do
tar -xf "$COMSOLDVD/archives/$COMSOL_TAR.isa" -C "$COMSOLROOT"
done
# Null the bin\tomcat\conf\login.properties
echo > "$COMSOLROOT/bin/tomcat/conf/login.properties"
# Mission complete
echo
echo All done! Enjoy!
echo
exit 0

Shell script to verify docker installation on Linux

I want to write a shell script which verifies whether docker is installed or not.
If docker is installed:
$ docker -v
Docker version 1.7.0, build 0baf609
$ echo $?
0
If docker is not installed:
$ docker -v
The program 'docker' is currently not installed. You can install it by typing:
apt-get install docker
$ echo $?
127
Here is my script:
#!/bin/bash
docker -v
if echo $? = 128 ; then
echo "The program 'docker' is currently not installed."
else
echo "Continuing with dockerized way"
fi
here for testing purpose, I ran it on the machine where docker is not installed, I kept 127 = 128, condition is wrong, so it should go in else, but still it prints The program 'docker' is currently not installed. I would like to know what I am missing here.
The correct syntax is:
if [ $? -eq 128 ]; then
...
To make it even more robust, you might want to check:
if [ $? -ne 0 ]; then
...

Environment Variables not set properly through script when ssh'ing into virtual machine

So I'm currently working on an LLVM compiler project and I'm running Ubuntu 14.04.2 LTS in VirtualBox on top of my MacBook Air.
I was given a bash script that sets up the required environment variables for the project. The script functions correctly if I source it from a terminal within the VM. However, I have port-forwarding enabled, that I'm using to ssh into the VM from my Mac's default terminal. But when I ssh into the VM and then try to run the script and set the environment variables, they aren't set properly.
Here is the script-
BASESCRIPT=$(readlink -f "$0")
BASE=$(dirname "$BASESCRIPT")
PROJ="cse231"
if [ -n "${VTENV}" ]; then
if [ "${BASE}" = "${VTENV}" -a "${PROJ}" = "${VTENV_NAME}" ]; then
echo "${VTENV_NAME} Virtual Environment is already active."
else
echo "There is already ${VTENV_NAME} Virtual Environment activated."
echo "(at ${VTENV})"
echo "Deactivate it first (using command 'deactivate_vtenv'), to activate"
echo "test environment."
fi
return 1
fi
export VTENV="${BASE}"
export VTENV_NAME="${PROJ}"
export CSE231ROOT="${VTENV}"
export LLVMBIN="${VTENV}/llvm/build/Release+Asserts/bin"
export LLVMLIB="${VTENV}/llvm/build/Release+Asserts/lib"
export BENCHMARKS="${VTENV}/extra/benchmarks"
export INSTRUMENTATION="${VTENV}/extra/instrumentation"
export OUTPUTLOGS="${VTENV}/logs"
echo "Activating ${VTENV_NAME} Virtual Environment (at ${VTENV})."
echo ""
echo "To exit from this virtual environment, enter command 'deactivate_vtenv'."
export "VTENV_PATH_BACKUP"="${PATH}"
export "VTENV_PS1_BACKUP"="${PS1}"
deactivate_vtenv() {
echo "Deactivating ${VTENV_NAME} Virtual Environment (at ${VTENV})."
echo "Restoring previous environment settings."
export "PATH"="${VTENV_PATH_BACKUP}"
unset -v "VTENV_PATH_BACKUP"
export "PS1"="${VTENV_PS1_BACKUP}"
unset -v "VTENV_PS1_BACKUP"
unset -v VTENV
unset -v VTENV_NAME
unset -v CSE231ROOT
unset -v LLVMBIN
unset -v LLVMLIB
unset -v BENCHMARKS
unset -v INSTRUMENTATION
unset -v OUTPUTLOGS
unset -f deactivate_vtenv
if [ -n "$BASH" -o -n "$ZSH_VERSION" ]; then
hash -r
fi
}
export PATH="${VTENV}/llvm/build/Release+Asserts/bin:${PATH}"
export PS1="[${VTENV_NAME}]${PS1}"
if [ -n "$BASH" -o -n "$ZSH_VERSION" ]; then
hash -r
fi
The problem I have is that the environment variable $BASE should be set as
"/home/user/cse231-proj", which it is when I source the script from the VM. But when I source it after ssh'ing in from my Mac's terminal, the environment is simply set as "." and all corresponding environment variables are extended from that, fudging any further commands I want to run using the environment variables.
What's going on here and why can't the script read the correct absolute path? How can I go about fixing this? Any help would be appreciated. Thanks.
When you log on via SSH, $0 is -bash when you source the script (or something similar) because it's a login shell. readlink sees that as another command-line argument and fails, leaving BASESCRIPT set to an empty string in your example, which means dirname returns the . you see.
Don't source the script in your current shell, run it instead. Then $0 will be the name of the script, and readlink -f $0 will return its full canonical path, and dirname will then emit the path to the script like it's supposed to.

Resources