简体   繁体   English

Ansible - 尝试 python3.5 时找不到 Virtualenv 可执行文件

[英]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.

相关问题 当我的 virtualenv 有 python3.5 时,为什么 django 1.9 继续使用 python2.7? - Why does django 1.9 keeps using python2.7 when my virtualenv have python3.5? 使用virtualenv时将python2.7软件包更改为我所需的python3.5软件包 - Change the python2.7 package to my required python3.5 package when use virtualenv 找不到python3.5 --version命令CentOS 7 - python3.5 --version command not found CentOS 7 在virtualenv中使用python3.5导入火炬时出现分段错误(核心转储) - Segmentation fault (Core dumped) on importing torch with python3.5 in virtualenv 运行python3 manage.py migration时Virtualenv(Python3.5 / pip3 / Django2.0 / psycopg2)中的错误 - Error in Virtualenv(Python3.5/pip3/Django2.0/psycopg2) when run python3 manage.py migrate 导入easygui时出现Python3.5错误 - Python3.5 erorr when import easygui 尝试安装模块时,即使 3.7 已经安装,pip 也会安装 python3.5 - When trying to install modules pip installs python3.5 even though 3.7 is already installed python3.5中的ValueError - ValueError in python3.5 无法在同一台计算机上使用Python3.5和Python2.7升级virtualenv - Unable to upgrade virtualenv with Python3.5 and Python2.7 on the same machine 安装 3.7 时,Tensorflow 更新强制 Python3.5 - Tensorflow Update Forcing Python3.5 when 3.7 installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM