Python Tutorial
https://www.w3schools.com/python/python_functions.asp
string
http://thepythonguru.com/python-strings/
https://www.tutorialspoint.com/python/string_startswith.htm
if var1 != var2:output to file
text_file = open("/tmp/debug", "w")
text_file.write("option1: %s\n" % option1)
text_file.write("value1: %s\n" % value1)
text_file.close()
PIP 2 under Ubuntu 20.04
https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/
#curl https://bootstrap.pypa.io/2.7/get-pip.py | sudo python2
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | sudo python2
pyenv
http://www.panticz.de/pyenv
Ansible
- name: Install Dependencies
apt:
name: ['python3-pip', 'python3-setuptools', 'python3.8', 'python3.8-venv']
state: latest
update_cache: yes
- name: Install AWSCLI
pip:
name: 'awscli'
virtualenv_python: /usr/bin/python3
pyenv
https://github.com/pyenv/pyenv-virtualenv
cat ./roles/openstack-lab-kolla/meta/requirements.yml
---
- src: avanov.pyenv# ansible-galaxy install avanov.pyenv
- hosts: vm1
roles:
- role: avanov.pyenv
pyenv_env: "user"
pyenv_setting_path: "~/.bashrc"
pyenv_path: "{{ ansible_env.HOME }}/.pyenv"
pyenv_owner: "{{ ansible_env.USER }}"
pyenv_update_git_install: no
pyenv_enable_autocompletion: no
pyenv_python_versions:
- "3.5.10"
pyenv_global: "3.5.10"
pyenv_virtualenvs:
- venv_name: "3.5.10"
py_version: "3.5.10"
tags: oscManually Intall / compile python 2.7 pyenv
apt install -y build-essential
# apt install -y libghc-zlib-dev
#apt install -y dpkg-dev
apt install -y libssl-dev zlib1g-dev
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar xzf Python-2.7.18.tgz
cd Python-2.7.18
./configure --enable-optimizations
sed -i 's/#zlib/zlib/' Modules/Setup
sudo make install
https://www.python.org/ftp/python/
# pip install --user imagesearch --break-system-packages
echo -e "[global]\nbreak-system-packages=true" > ~/.config/pip/pip.confIntall python 2.7 pyenv
sudo apt install -y git build-essential libbz2-dev libreadline-dev libssl-dev zlib1g-dev libsqlite3-dev wget curl libncurses5-dev libncursesw5-dev xz-utils libffi-dev liblzma-dev
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\n eval "$(pyenv init -)"\n eval "$(pyenv virtualenv-init -)"\nfi' >> ~/.bashrc
pyenv install 2.7.18
pyenv local 2.7.18
pyenv virtualenv 2.7.18 python2
ln -s /root/.pyenv/shims/python2 /usr/bin/python2Check / Fix ImportError: No module named xxx
ImportError: No module named docker
# check
python2 -c "import docker"
# Install pip docker module
pip install docker