Help trying to build swift. No module six in build_swift/argparse/actions.py

I've trying to follow the build instructions on https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#cloning-the-project
Everything cloned correctly. All the dependencies have at least the required level. But when I try and build I get this message relating to one of the python files trying to import a "module six". Does anyone know how one might fix this please?

Traceback (most recent call last):
File "utils/build-script", line 26, in
from build_swift.build_swift import argparse
File "....../Developer/swift-project/swift/utils/build_swift/build_swift/argparse/init.py", line 25, in
from .actions import Action, Nargs
File "........./Developer/swift-project/swift/utils/build_swift/build_swift/argparse/actions.py", line 21, in
import six
ModuleNotFoundError: No module named 'six'

The six module is a Python compatibility module used to smooth over some differences between Python 2 and 3. You can fix this on your system by running pip install six or if you have both Python 2 and 3 installed, use pip3 install six.

Thank you for the speedy answer.

I ran pip3 install six and got a message saying successfully installed 21.1.1 but to run another command to 21.1.2 which I then did.

But I'm still getting the same ModuleNotFoundError: No module named 'six'? Is there something else I have to do to make it 'visible' to the builder? Many thanks

You might be running build-script using a different Python interpreter then. If you have both Python 2 and 3 installed it could be using Python 2 by default.

Are you building on macOS? If so it will prefer /usr/bin/python which is Python 2.7.10 last I checked. You'd want to run pip install six then, which should use the pip from the default Python 2.

Thanks for the help Ross. Yes on macOS as want to be able to look at swift source code in Xcode and this seems the only way.

That sounds a reasonable explanation. I don't know much about python but had heard there were two different versions. However if I run pip install six now I just get the following reply:
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (1.16.0)
Any idea how to put it into 2.7.10? [Current in the swift-project/swift dir.]

Looks like you have Python 3.9 installed using something like Homebrew. How are you running build-script?

You might be able to run it using python3 utils/build-script <ARGS> instead of just utils/build-script <ARGS> which is selecting a different Python version.

Hi Ross, I tried that this morning with unfortunately the same result. Screen shot attached. I'm running build-script and ARGS just as suggested on the GitHub site here: swift/GettingStarted.md at main · apple/swift · GitHub
in the section "The actual build" number 3. I'm not sure I really understand the build process but it looks as if it's being done with 'ninja'. Perhaps this or 'cmake' are invoking the wrong version of python?

After some further digging, I've finally got it building by editing the top of the build-script file and changing 1st line from "#!/usr/bin/env python" to "#!/usr/bin/python3"
I'm not entirely sure what dropping the "env" does [but it didn't work with that still there], and it seems a bit nutty that someone following these instructions on the Swift site should be having to poke around inside the actual building script files and changing things to get it to work, but that's for the Swift team. Thank you very much for you insights which pushed me in the right direction.
I don't yet know if it's been successful, as has been building for over an hour, but upto 61% so definitely doing something!

Sorry for not getting back sooner. Didn't realize there was more updates in this thread.

I'm glad you were able to get it working. I wouldn't expect the "shebang" at the top of the file would impact how the script would run when invoked with python3 explicitly. You shell would typically use that information to decide which python to use when running the script as a standalone executable.

It's possible that python3 in your shell PATH is pointing to something other than /usr/bin/python3. Pretty sure /usr/bin/python3 will point to the Python 3 that ships in the Xcode developer tools now. If you have another Python 3 installed that would take precedence in your shell PATH and didn't have six installed with the corresponding pip3 this failure would make sense.

Terms of Service

Privacy Policy

Cookie Policy