roots / trellis

WordPress LEMP stack with PHP 8.2, Composer, WP-CLI and more
https://roots.io/trellis/
MIT License
2.51k stars 607 forks source link

Failed to install pip on vagrant provision #1267

Closed schuhwerk closed 3 years ago

schuhwerk commented 3 years ago

Description

While provisioning with vagrant today I come across this issue:

curl https://bootstrap.pypa.io/get-pip.py | sudo python

Stdout from the command:

Stderr from the command:

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1883k 100 1883k 0 0 4379k 0 --:–:-- --:–:-- --:–:-- 4369k
Traceback (most recent call last):
File “”, line 24226, in
File “”, line 199, in main
File “”, line 82, in bootstrap
File “/tmp/tmpagSXn5/pip.zip/pip/_internal/cli/main.py”, line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax

Steps to reproduce

Just run vagrant provision.

Expected behavior: No Error...

Actual behavior: The Error...

Reproduces how often: Always.

Versions

Windows 10. vagrant --version: 2.2.15

Solution

Looks like bootstrap.pypa.io has moved their python2 installer from:

Changing the url in the Vagrantfile fixed the issue for me.

More

Im not the only one with the issue:

Thank you for your work!

swalkinshaw commented 3 years ago

Thanks for the details @schuhwerk

The fix in the Vagrantfile is simple but it depends on the local (to the VM) version of Python. So to properly fix it we should check the Python version and use the proper URL which is a bit annoying but not terrible.

tangrufus commented 3 years ago

What if we drop python 2 support?

swalkinshaw commented 3 years ago

@TangRufus I was thinking about that again last night... we probably should now. It's becoming too much of a burden to support and we're past the Python 2 sunset date.

mkcy3 commented 3 years ago

Changing the URL in the vagrantfile has not worked for me

@swalkinshaw you mentioned the need to check the version of python on the VM, would you be able to post a solution to that? I just started using Trellis yesterday so its all very new to me.

schuhwerk commented 3 years ago

@mkcy3 There is another issue with the versioning:

# trying version compare in Vagrantfile
if '2.2.15' <= '2.2.5'
        fail_with_message "its smaller!"
end

This fails. So you might have to comment out the version check surrounding the ansible.pip_install_cmd.

#if Vagrant::VERSION >= '2.2.5'
     # Fix for https://github.com/hashicorp/vagrant/issues/10950
     ansible.pip_install_cmd = 'curl https://bootstrap.pypa.io/2.7/get-pip.py | sudo python'
#end
swalkinshaw commented 3 years ago

It might be easier to force it to use Python 3. Something like this:

if local_provisioning?
  ansible.extra_vars = { ansible_python_interpreter:"/usr/bin/python3" }
  ansible.install_mode = 'pip'
  ansible.pip_install_cmd = 'curl https://bootstrap.pypa.io/get-pip.py | sudo python3'
  ansible.provisioning_path = provisioning_path
  ansible.version = vconfig.fetch('vagrant_ansible_version')
end

I'll be looking into a proper fix

schuhwerk commented 3 years ago

@swalkinshaw I tried that before, too. I get:

Stdout from the command:

Stderr from the command:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1883k  100 1883k    0     0  4494k      0 --:--:-- --:--:-- --:--:-- 4494k
Traceback (most recent call last):
  File "<stdin>", line 24226, in <module>
  File "<stdin>", line 199, in main
  File "<stdin>", line 82, in bootstrap
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/cli/main.py", line 8, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/cli/autocompletion.py", line 9, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/cli/main_parser.py", line 7, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/cli/cmdoptions.py", line 22, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/cli/progress_bars.py", line 9, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/utils/logging.py", line 14, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/utils/misc.py", line 29, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "/tmp/tmp2q8yhghw/pip.zip/pip/_internal/locations.py", line 11, in <module>
ModuleNotFoundError: No module named 'distutils.command'
mkcy3 commented 3 years ago

@schuhwerk i added python3 disutils and had to downgrade ntp galaxy role as per this discourse discussion

That configuration works for me

swalkinshaw commented 3 years ago

https://github.com/roots/trellis/pull/1269 updates Vagrant to always use python3. I think it makes you, but run vagrant box update to get the latest Ubuntu box version as well.