2

For all the good fellars out there who're trying to get started on docker-compose. I'm running OS X El Capitan (10.11).

The system ships with python 2.7. Trying to replace the system python to python 3 isn't recommended because many core systems depend on python 2 libraries.

Installed 'Docker' for Mac and 'docker-compose' using docker in the command-line.

Going to terminal: 'docker-compose --version' throws error:

    admins-MacBook-Pro-63:~ apil.tamang$ docker-compose --version
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 9, in <module>
    load_entry_point('docker-compose==1.8.1', 'console_scripts', 'docker-compose')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 357, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2394, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2108, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/Library/Python/2.7/site-packages/compose/cli/main.py", line 17, in <module>
    from ..bundle import get_image_digests
  File "/Library/Python/2.7/site-packages/compose/bundle.py", line 14, in <module>
    from .service import format_environment
  File "/Library/Python/2.7/site-packages/compose/service.py", line 31, in <module>
    from .parallel import parallel_execute
  File "/Library/Python/2.7/site-packages/compose/parallel.py", line 10, in <module>
    from six.moves import _thread as thread
ImportError: cannot import name _thread

What do you do? Just installing python3 doesn't fix it!

apil.tamang
  • 2,545
  • 7
  • 29
  • 40
  • You used the first compose install command shown [here](https://docs.docker.com/compose/install/#/install-docker-compose) right? – idjaw Oct 27 '16 at 12:58
  • I'm not sure which method I used. It probably was using pip, since that seems like the most straight-forward way. – apil.tamang Oct 27 '16 at 13:35
  • Yes, you are installing at system level using the default Python. Is this your intention? I would suggest doing this in a virtualenv instead. You *did* mention that you want to do this in python 3. So why not just set up a virtualenv in python 3 and pip install inside that virtualenv instead? – idjaw Oct 27 '16 at 13:44
  • Also, *please* do not replace the system version. Leave the system version alone. This is required by the OS. You can install multiple versions of Python alongside each other and use a virtualenv to keep things contained and out of system space. – idjaw Oct 27 '16 at 13:46

3 Answers3

2

this solved my issue

pip install --upgrade docker-py

.

Oshan Wisumperuma
  • 1,808
  • 1
  • 18
  • 32
0

The error stems from the fact that python can't locate the 'six' modules. First I did:

sudo pip install six -U //updates the six modules in python

That didn't help any better, so I did the following from my terminal:

python -c 'import six; print(six.__version__)'

For me this printed out the following:

/usr/local/bin/python2.7/site-packages/

which is what let me know WHERE my six modules were located. Now, if you look at the error-stack from python I posted at the beginning of this question, you'll see that all the actions are happening in the folder: /Library/Python/2.7/site-packages. This was the AHAA ! moment for me. For some reason, the docker-compose python files were installed in this folder and NOT in my system python path (i.e. /usr/local/bin/python). I have no idea why!

Then I had to copy six.py and six.pyc to the /Library using the following command:

cp /usr/local/bin/python2.7/site-packages/six.* /Library/Python/2.7/site-packages

Do a little bit of research here guys, don't give up! Don't blindly type the commands above. Long story short, copying the file to /Library/Python/2.7/site-packages does the deal and now I'm on my way to using docker-compose.

apil.tamang
  • 2,545
  • 7
  • 29
  • 40
  • I would probably avoid modifying the system level Python 2.7. That one is there as a requirement for the OS. The ideal approach here would be to probably use a virtualenv to not pollute system space. – idjaw Oct 27 '16 at 13:45
  • @idjaw When you meant the 'system' level Python, you mean the one in /usr/local/bin/python2.7/..' yes? I assumed that is what the system python was for me. I read in a couple of other threads about updating the 'six' modules and no-one really seemed to have any issues. – apil.tamang Oct 27 '16 at 17:56
  • In retrospect, the entire purpose of the 'six' modules seem to allow python 2 to inter-operate against python 3 dependent libraries. Hence, at least with this (the 'six' module), I assume an update wouldn't be risky. Well.. let's just wait and find out! Also, I didn't know about 'virtualenv', but if I had to go back and redo it, as you said, I might pursue the latter now. – apil.tamang Oct 27 '16 at 17:59
0
sudo pip install --ignore-installed six

source

i_love_nachos
  • 411
  • 1
  • 4
  • 14
  • Although this code might solve the problem, a good answer should also contain a explanation. – BDL Feb 10 '17 at 14:50