gpt4 book ai didi

python-3.x - 如何使用 Ansible 安装 python3.4.3

转载 作者:行者123 更新时间:2023-12-01 09:53:57 25 4
gpt4 key购买 nike

我想通过使用 pyenv 和 ansible 来安装 python3.x。

- name: install pyenv
git: >
repo=https://github.com/pyenv/pyenv.git
dest=/home/www/.pyenv
accept_hostkey=yes
become: yes
become_user: www

- name: enable pyenv
shell: |
echo 'export PYENV_ROOT="/home/www/.pyenv"' >> /home/www/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> /home/www/.bashrc
echo 'eval "$(pyenv init -)"' >> /home/www/.bashrc
- name: install python
shell: pyenv install 3.4.3

如何用 ansible 安装 python3.x?

最佳答案

因此,这对我来说很有效,可以使用 ansible 安装任何版本的 python 并使其成为替代安装。我先跑了configuremake ,后来压缩了结果,因为这需要一段时间,然后使用镜像重新分发文件,以便我可以运行 make altinstall在其自己的。这是食谱:

---
# Check the alt python3 version
- name: check alt python version
shell: /usr/local/bin/python3.6 --version
register: python3_version
ignore_errors: yes # If not installed
tags:
- python-alt

# Stuff I did manually to compile everything first by hand
# Python3 alt-install - steps to create binary:
# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
# tar xf Python-3.6.4.tgz
# mv Python-3.6.4 Python-3.6.4-binary && cd Python-3.6.4-binary
# ./configure --prefix=/usr/local --enable-optimizations
# cd .. && tar -zcvf Python-3.6.4-binary.tar.gz Python-3.6.4-binary (upload to mirror servers)
# make && sudo make altinstall UNINST=1
- name: download and unpack alternative python3
unarchive:
src: http://www.yourmirror.com/centos/python/Python-3.6.4-binary.tar.gz dest=/tmp/Python-3.6.4-binary.tar.gz
dest: /tmp
remote_src: yes
keep_newer: yes
when: python3_version['stderr'] != 'Python 3.6.4'
tags:
- python-alt

# Its possible to install (instead of altinstall) python3 here
- name: make install alt python3
make:
chdir: /tmp/Python-3.6.4-binary
target: altinstall
params:
UNINST: 1 # Replace
when: python3_version['stderr'] != 'Python 3.6.4'
become: yes
tags:
- python-alt

- name: download get-pip.py
get_url:
url: https://bootstrap.pypa.io/get-pip.py
dest: /tmp/get-pip.py
mode: 0664
tags:
- python-alt

- name: install pip for python3
shell: /usr/local/bin/python3.6 /tmp/get-pip.py
become: yes
tags:
- python-alt

# We need virtualenv installed under py3 for the virtualenv command to work
- pip:
name: virtualenv
executable: /usr/local/bin/pip3.6
become: True
tags:
- python-alt

如果你想在你的服务器上编译所有东西,你可以在 altinstall 之前执行以下操作步骤并下载源代码包而不是预编译的 tar。我不建议这样做,因为它确实会占用资源,而且您不想在 prod 中这样做。以 Python2.7.14 为例:
---
# Build the default target
- debug:
var: python2_version
tags:
- python_alt
- make:
chdir: /tmp/Python-2.7.14-binary
when: python2_version['stderr'] != 'Python 2.7.14'
tags:
- python_alt
- name: configure target command
command: ./configure --prefix=/usr/local --enable-optimizations chdir=/tmp/Python-2.7.14-binary
when: python2_version['stderr'] != alt_python_version
tags:
- python_alt

关于python-3.x - 如何使用 Ansible 安装 python3.4.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32546506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com