[英]Ansible - Virtualenv executable not found when trying python3.5
Is there a way to fix the pip module not being able to find the right python version?有没有办法修复 pip 模块无法找到正确的 python 版本? The key issue seems to be with virtualenv_python
关键问题似乎与virtualenv_python
- name: Create venv and install requirements
pip:
requirements: /home/admin/dev/python/filepro/requirements.txt
virtualenv: /home/admin/venvs/filepro
virtualenv_python: python3.5
tags:
- venv
The error:错误:
Error message:
FAILED! => {"changed": false, "failed": true, "msg": "Failed to find required executable virtualenv"}
/usr/bin/python3.5
is where python 3.5 is and I'm using Ansible 2.2.1.0
/usr/bin/python3.5
是 python 3.5 所在的位置,我使用的是Ansible 2.2.1.0
First, you need to make sure virtualenv is installed for the version of Python you intend to use.首先,您需要确保为您打算使用的 Python 版本安装了 virtualenv。 You can do that prior running the pip module by:您可以在运行 pip 模块之前通过以下方式执行此操作:
- name: Install virtualenv via pip pip: name: virtualenv executable: pip3
If you don't want (or cannot) install virualenv as root, Ansible will fail to pick up the virtualenv executable.如果您不想(或不能)以 root 身份安装 virualenv,Ansible 将无法获取 virtualenv 可执行文件。 You can add it manually to the PATH environmental variable:您可以手动将其添加到 PATH 环境变量中:
- name: Create venv and install requirements pip: requirements: /home/admin/dev/python/filepro/requirements.txt virtualenv: /home/admin/venvs/filepro virtualenv_python: python3.5 tags: - venv environment: PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin"
Alternatively, you can install vitualenv as a root user:或者,您可以以 root 用户身份安装 vitualenv:
- name: Install virtualenv via pip pip: name: virtualenv executable: pip3 become: yes become_user: root
you can use the following to create a virtual env using the python3-venv
module您可以使用以下内容使用python3-venv
模块创建虚拟python3-venv
First of all, you need to have python3-venv
package in your destination server首先,你需要在你的目标服务器中有python3-venv
包
install it using $ sudo apt install python3-venv
使用$ sudo apt install python3-venv
安装它
then in your ansible task you can create the virtual env as follows然后在您的 ansible 任务中,您可以创建虚拟环境,如下所示
- name: "Setup Virtual Env",
pip:
- requirements: path/to/requirements.txt # this is optional
- virtualenv: path/to/required/virtual_env_destination
- virtualenv_command: 'python3 -m venv'
No need to use virtualenv_python
parameter as well也不需要使用virtualenv_python
参数
The problem was that virtualenv was not installed as sudo.问题是 virtualenv 没有安装为 sudo。
Please correct me if I'm wrong, but appears that to get the pip module to work with virtualenv you need to run sudo pip install virtualenv
如果我错了,请纠正我,但似乎要让 pip 模块与 virtualenv 一起使用,您需要运行sudo pip install virtualenv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.