puppet-python icon indicating copy to clipboard operation
puppet-python copied to clipboard

python3-venv missing ? pip3 missing in the virtualenv ?

Open Furiouss38 opened this issue 6 years ago • 4 comments

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 4.8.2
  • Ruby: 2.3.3p222
  • Distribution: debian 9.5
  • Module version: last 2.1.1

How to reproduce (e.g Puppet code you use)

class { 'python' :
  version    => 'python3',
  pip        => 'present',
  dev        => 'absent',
  virtualenv => 'present',
  gunicorn   => 'absent',
}
package {'python3-venv':
ensure => present,
}->
python::pyvenv  { '/data/python/.virtualenvs' :
  ensure       => present,
  systempkgs   => true,
  owner        => 'pod',
  group        => 'pod',
}

python::pip { 'virtualenvwrapper' :
  ensure        => 'present',
  pip_provider  => 'pip3',
  pkgname       => 'virtualenvwrapper',
  proxy         => 'someproxy:3128',
  virtualenv    => '/data/python/.virtualenvs',
  owner         => 'pod',
  timeout       => 1800,
}

What are you seeing

It's probably a problem of how I use the module but I had to add

package {'python3-venv':
ensure => present,
}->

to have python::pyvenv working because i had :

Error: /Stage[main]/Main/Node[pod-web-test.grenet.fr]/Python::Pyvenv[/data/python/.virtualenvs]/Exec[python_virtualenv_/data/python/.virtualenvs]/returns: change from notrun to 0 failed: Could not find command 'pyvenv'

and I had to do a symlink of pip3 to have it in my virtualenv ln -s /usr/bin/pip3 /data/python/.virtualenvs/bin/pip3

What am I missing in my use of the module so I don't have to do the fix I did ? I turned the readme upside down and didn't found an answer (I don't know python but I have to install a python app on my server so I'm trying to write the requierement in puppet instead of following the app's doc that explain how to do it by hand)

Furiouss38 avatar Sep 11 '18 09:09 Furiouss38

@Furiouss38 This is how i use it. The example in the readme shows with system, but its pretty much the same. Let me know if this works for you, and then we can update the readme to include a python3 example.

python::virtualenv { '/data/python/.virtualenvs' :
          ensure     => present,
          version    => '3',
          systempkgs => true,
          owner      => 'root',
          group      => 'root',
          timeout    => 0
}

danquack avatar Sep 12 '18 01:09 danquack

Hi, Thanks for your answer. I tried that instead of my python::pyvenv with adding my proxy because my servers are behind a proxy. It's not working but I know why. I had the following error :

Error: true && export http_proxy=http://proxy:3128 && virtualenv --system-site-packages -p python3 /data/python/.virtualenvs && /data/python/.virtualenvs/bin/pip --log /data/python/.virtualenvs/pip.log install  --proxy=http://proxy:3128  --upgrade pip && /data/python/.virtualenvs/bin/pip install  --proxy=http://proxy:3128  --upgrade distribute returned 1 instead of one of [0]
Error: /Stage[main]/Main/Node[pod-web-test.grenet.fr]/Python::Virtualenv[/data/python/.virtualenvs]/Exec[python_virtualenv_/data/python/.virtualenvs]/returns: change from notrun to 0 failed: true && export http_proxy=http://proxy:3128 && virtualenv --system-site-packages -p python3 /data/python/.virtualenvs && /data/python/.virtualenvs/bin/pip --log /data/python/.virtualenvs/pip.log install  --proxy=http://proxy:3128  --upgrade pip && /data/python/.virtualenvs/bin/pip install  --proxy=http://proxy:3128  --upgrade distribute returned 1 instead of one of [0]

I tried to run it manualy to see where it fails, it here :

export http_proxy=http://proxy:3128 && virtualenv --system-site-packages -p python3 /data/python/.virtualenvs

it crashed with a shitload of errors including some networking errors

 File "/data/python/.virtualenvs/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connection.py", line 147, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6a5c31ed68>: Failed to establish a new connection: [Errno 101] Le réseau n'est pas accessible

so i tried to add

export HTTPS_PROXY=http://proxy:3128

and then it worked :

root@pod-web-test:~# virtualenv --system-site-packages -p python3 /data/python/.virtualenvs
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /data/python/.virtualenvs/bin/python3
Not overwriting existing python script /data/python/.virtualenvs/bin/python (you must use /data/python/.virtualenvs/bin/python3)
Installing setuptools, pkg_resources, pip, wheel...done.
root@pod-web-test:~#

so maybe the module needs to export both http_proxy and https_proxy env variables ?

Furiouss38 avatar Sep 12 '18 07:09 Furiouss38

Without deep diving into the code for how proxying works, just going to drop this line. Might be an opportunity to create a PR. https://github.com/voxpupuli/puppet-python/blob/2f16648a91b6c7942b34950a88d7d5a6b386c9b6/manifests/virtualenv.pp#L128

danquack avatar Sep 12 '18 21:09 danquack

We're happy to review a PR for this :)

bastelfreak avatar Sep 15 '18 13:09 bastelfreak