How can I install the latest Anaconda with wget - python

I'm looking at installing anaconda via wget on my server. I've come across https://askubuntu.com/questions/505919/installing-anaconda-python-on-ubuntu and http://ericjonas.com/anaconda.html and it looks promising . As of this writing the current version( https://www.continuum.io/downloads#_unix ) is 4.0 . How can I wget the latest version.

wget just downloads the file...
for python 2.7 :
wget https://repo.continuum.io/archive/Anaconda2-2018.12-Linux-x86_64.sh
for python3.X:
wget https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh
This is a shell script that guides you though the install.
Run the following line inside of the folder of the downloaded file to start the guided install...
for python 2.7:
bash Anaconda2-2018.12-Linux-x86_64.sh
for Python 3.X:
bash Anaconda3-2018.12-Linux-x86_64.sh
Check latest repos or if you want any specific version here:
https://repo.continuum.io/archive/

This will download the latest anaconda version from scraping the html from the website:
wget -O - https://www.anaconda.com/distribution/ 2>/dev/null | sed -ne 's#.*\(https:\/\/repo\.anaconda\.com\/archive\/Anaconda3-.*-Linux-x86_64\.sh\)\">64-Bit (x86) Installer.*#\1#p' | xargs wget

wget \
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh \
&& eval "$(/home/$USER/miniconda3/bin/conda shell.bash hook)"\
&& conda init

You can write the following bash script to automate the installing process.
cd ~
wget https://repo.continuum.io/archive/Anaconda3-2020.11-Linux-x86_64.sh
bash Anaconda3-2020.11-Linux-x86_64.sh -b -p ~/anaconda3
rm Anaconda3-2020.11-Linux-x86_64.sh
echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc
# Reload default profile
conda init
source ~/.bashrc

I would just go to https://repo.anaconda.com/archive/ and copy the link of the most recent dated release and use wget with that.
For example, right now it would be:
wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
If you want a more automatic way you could try the following.
Using #philipper solution as a starting point I made some modifications.
latest=$(wget -qO- https://repo.anaconda.com/archive/ |
grep -Eo "(href=\")(Anaconda3-.*-Linux-x86_64.sh)*\"" |
sed 's/href=//g' | sed 's/\"//g' | head -n 1); wget "https://repo.anaconda.com/archive/$latest"
The script will download the html of the repo archive page.
Parse out all href tags matching Anaconda3 for Linux-x86 _64 (1st sed).
I strip out the "href=" and quotes from that output (2nd & 3rd sed).
I then get the first entry which will be the most recent and set it to the variable latest. Then use wget to download from the full url.
Either way, once it's downloaded you'll most likely need to make the .sh file executable then you can just run it like a normal .sh file.
I would just do it the first way but the second way does work for now at least.
I'm not really good at bash or using sed so my "automatic" solution might have some issues.

How to install latest Anaconda (2022)
$ ANACONDA_VERSION=$(curl -sS https://repo.anaconda.com/archive/ | grep -Po '(?<=Anaconda3-)([0-9.]*)(?=-Linux-x86_64)' | head -n1)
$ ANACONDA_URL="https://repo.anaconda.com/archive/Anaconda3-${ANACONDA_VERSION}-Linux-x86_64.sh"
$ wget $ANACONDA_URL && bash $(basename $ANACONDA_URL) -b
https://repo.anaconda.com/archive/ lists the release anaconda installer binaries, in the order of latest released.
The grep command grep -Po '(?<=Anaconda3-)([0-9\\.]*)(?=-Linux-x86_64)' extracts the \d\d\d\d.\d\d string, where Anaconda3- and -Linux-x86_64 are lookahead patterns. grep -Po is a useful, clean command to extract some regex pattern from a string (one could do with sed as well).
| head -n1 : choose whichever comes the first, i.e. the latest release.
Miniforge / Miniconda (automatic latest):
$ MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh"
$ wget $MINIFORGE_URL && bash $(basename $MINIFORGE_URL) -b
$ MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"
$ wget $MINICONDA_URL && bash $(basename $MINICONDA_URL) -b
Remarks
Note: the -b option is for the "batch mode" -- no question asked, accept the license, etc. and just install the anaconda for you. One may also find the option -p $CONDA_PREFIX useful.

Related

./configure doesn't work on python 3.8.2 on windows

I am trying to execute the code:
./configure \
--prefix "$(dirname $(pwd))" \
--with-openssl=$(openssl version -d | sed -r 's/OPENSSLDIR: "([^"]*)"/\1/') \
&& make && make install
popd
this error is recived:
File "<ipython-input-7-f69304efaff4>", line 1
./configure
^
SyntaxError: invalid syntax
Does anyone know how to fix it?
This code should be executed in bash shell, not python
It should be executed in bash shell but as i am using windows it was not possible.
In this code i was trying to install FreeTDS and after download the stable realease and the binaries for windows I was able to install it by using the windows powershell to run the .ps1 file

Unable to uninstall python 2.7 in mac os

I have python 2.7 installed on my macbook pro in /usr/bin. When I do ls python* I see these files: python python-config python2.7 python2.7-config pythonw pythonw2.7.
I want to delete them but I can't find a way to do it, I've tried sudo rm -rf and other things but nothing seems to work.
When I do sudo rm -rf I get this:
rm: python: Operation not permitted,
and when I do sudo rm python I get this
override rwxr-xr-x root/wheel restricted,compressed for python?
I want to delete python entirely from my system , can someone help me?
Do not remove python 2.7 from your Mac computer. As you have seen you probably can't anyway. The Mac uses python and the files are protected to be sure they are not removed.
If you want to run another version of python install it and set up virtual environments.
Referenced here
# sudo rm -rf /Library/Frameworks/Python.framework
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
cd /usr/local/bin && \
sudo ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | xargs rm
Lol can't believe no one has said this:
Boot into recovery, turn off SIP:
csrutil disable
restart,
open terminal
cd /usr/bin
then
sudo chmod -R 777 ./
try it again
$ python --version
you should no longer see it

Python script can't access some environment variables

I am building Docker Image FROM node:8.9.3-alpine (which is Debian) and then running it as usual and passing parameters like this:
docker run -dt \
-e lsRegion=${bamboo_lsRegion} \
-e lsCluster=${bamboo_lsCluster} \
Then inside that container I am exporting some variables and when I echo them, I can see proper value
export lsEnv=${lsEnv:-'dev'}
Later in scripts I run python script and when I run the print(os.environ) I can see all the variables from docker run like lsRegion but I do not see the newly exported one like lsEnv.
I already found and tried to solve with this: Python: can't access newly defined environment variables by calling the source ~/.bashrc but I cannot find that file.
I have tried
~/.bashrc
/etc/bash.bashrc
/root/.bashrc
But neither of those exist (also does not know if this solve my problem) and it ends with this error message /app/deploy.sh: source: line 16: can't open '/root/.bashrc'
More reproducible example:
Dockerfile
FROM node:8.9.3-alpine
RUN apk add --no-cache \
python \
py-pip \
ca-certificates \
openssl \
groff \
less \
bash \
curl \
jq \
git \
zip \
build-base \
&& pip install --no-cache-dir --upgrade pip awscli \
&& aws configure set preview.cloudfront true
ENV TERRAFORM_VERSION 0.11.10
RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform.zip -d /usr/local/bin && \
rm -f terraform.zip
RUN apk -v --update add python py-pip
RUN pip install --upgrade awscli
RUN pip install --upgrade boto3
COPY ./build.variables /app/build.variables
COPY ./aws/taskdef/template.json /app/template.json
COPY ./deploy.sh /app/deploy.sh
COPY ./deploy.py /app/deploy.py
COPY ./terraform /app/terraform
CMD ["sh", "/app/deploy.sh"]
deploy.sh
#!/bin/bash -x
cd /app/terraform
./run-terraform.sh
cd ..
python /app/deploy.py
terraform/run-terraform.sh
...
export lsEnv="NotThere"
...
python script
#!/usr/bin/env python
import os
print(os.environ)
The print will show lsRegion or lsCluster but it will not show the lsEnv
Inside deploy.sh, you need to source run-terraform.sh if you want to affect the environment of the process that runs deploy.py, rather than the environment created for the process that runs run-terraform.sh.
#!/bin/bash -x
cd /app/terraform
source ./run-terraform.sh
cd ..
python /app/deploy.py
(You could also use . ./run-terraform.sh; source is a more readable bash synonym for the POSIX . command, but . is necessary if you are using some other POSIX-compliant shell that doesn't support source.)
I solve it by calling this command in terraform/run-terraform.sh for each environment variable I will need in python script:
echo "export lsTargetGroup=$lsTargetGroup" >> ~/.bashrc
And then in deploy.sh I just add source ~/.bashrc before calling python script

Setting virtualenv to use a compiled from source python as bin

I need to force a virtualenv to use a compiled source python on my ci server (long story short: travis ci support python 2.7.3. heroku works with 2.7.6 and we insist on testing in the same environment as production) . But I fail to get virtualenv to run against it.
travis first runs this script:
if [ ! -d ./compiled ]; then
echo "creating compiled folder"
mkdir compiled
else
echo "compiled exists"
fi
cd compiled
if [ ! -e Python-2.7.6.tar.xz ]; then
echo "Downloading python and compiling"
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure
make
chmod +x ./python
else
echo "Compiled python exists!"
fi
and then:
- virtualenv -p ./python ./compiled/python276
- source ./compiled/python276/bin/activate
but when then doing python --version shows 2.7.3 instead of 2.7.6
Guess I'm missing something, Thanks for the help!
Go to the virtualenv folder, and open bin/ folder:
~/.Virtualenv/my_project/bin
Remove 'python' file, and create a symbolic link to the python executable, that you want to use, like:
cd ~/.Virtualenv/my_project/bin
mv python python-bkp
ln -s /usr/bin/python .

How to manually pass source of bzip2 install for Python install?

I've been through several StackOverflow questions about Python & bzip2. These have been very helpful in getting me to the state I'm clearly at now. Here's what I've done so far and the problem I'm having:
I do not have root access and cannot install libbz2-dev(el)
/usr/bin/bzip2 is version 1.0.3
/usr/bin/python is version 2.4.3
GNU Stow is being used to manage libraries similar to how homebrew works
I need Python 2.7.3 to install with the bzip2 module in order to properly compile node.js from source. And yes, I'm sorry, but I do actually have to do all of this as a regular user from source.
I have installed bzip2 from source as follows:
$ make -f Makefile-libbz2_so
$ make
$ make install PREFIX=${STOW}/bzip2-1.0.6
$ cp libbz2.so.1.0.6 ${STOW}/bzip2-1.0.6/lib/
$ cd ${STOW}/bzip2-1.0.6/lib
$ ln -s libbz2.so.1.0.6 libbz2.so.1.0
$ cd ${STOW}
$ stow bzip2-1.0.6
I have stow's root directory in my PATH before anything else, so this results in:
$ bzip2 -V
# [...] Version 1.0.6
Which indicates that the correct bzip2 is being utilized in my PATH.
Next I move on to compiling Python from source and run the following:
$ cd Python-2.7.3
$ ./configure --prefix=${STOW}/Python-2.7.3
$ make
# Complains about several missing modules, of which "bz2" is the one I care about
$ make install prefix=${STOW}/Python-2.7.3 # unimportant as bz2 module failed to install
What is the correct way to tell Python during it's source configuration where the source installed bzip 1.0.6 library lives so it will detect the bzip2 devel headers and install the module properly?
Alright, it took me a few months to get to this, but I'm finally back and managed to tackle this problem.
Install bzip2 from source:
# Upload bzip2-1.0.6.tar.gz to ${SRC}
$ cd ${SRC}
$ tar -xzvf bzip2-1.0.6.tar.gz
$ cd bzip2-1.0.6
$ export CFLAGS="-fPIC"
$ make -f Makefile-libbz2_so
$ make
$ make install PREFIX=${STOW}/bzip2-1.0.6
$ cp libbz2.so.1.0.6 ${STOW}/bzip2-1.0.6/lib/
$ cd ${STOW}/bzip2-1.0.6/lib
$ ln -s libbz2.so.1.0.6 libbz2.so.1.0
$ cd ${STOW}
$ stow bzip2-1.0.6
$ source ${HOME}/.bash_profile
$ bzip2 --version
#=> bzip2, a block-soring file compressor. Version 1.0.6...
Install Python from source:
# Upload Python-2.7.3.tar.gz to ${SRC}
$ cd ${SRC}
$ tar -xzvf Python-2.7.3.tar.gz
$ cd Python-2.7.3
$ export CLFAGS="-fPIC"
$ export C_INCLUDE_PATH=${STOW}/../include
$ export CPLUS_INCLUDE_PATH=${C_INCLUDE_PATH}
$ export LIBRARY_PATH=${STOW}/../lib
$ export LD_RUN_PATH=${LIBRARY_PATH}
$ ./configure --enable-shared --prefix=${STOW}/Python-2.7.3 --libdir=${STOW}/../lib
$ make
$ make install prefix=${STOW}/Python-2.7.3
$ cd ${STOW}
$ stow Python-2.7.3
$ source ${HOME}/.bash_profile
$ python -V
#=> Python 2.7.3
$ python -c "import bz2; print bz2.__doc__"
#=> The python bz2 module provides...
Although node.js wasn't technically part of the question, it is what drove me to go through all of the above so I may as well include the last few commands to get node.js installed from source using a source install Python 2.7.3 & bzip2 1.0.6:
Install node.js from source:
# Upload node-v0.10.0.tar.gz to ${SRC}
$ cd ${SRC}
$ tar -xzvf node-v0.10.0.tar.gz
$ cd node-v0.10.0
$ ./configure --prefix=${STOW}/node-v0.10.0
$ make
$ make install prefix=${STOW}/node-v0.10.0
$ cd ${STOW}
$ stow node-v0.10.0
$ source ${HOME}/.bash_profile
$ node -v
#=> v0.10.0

Categories

Resources