Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named urllib.parse #1288

Closed
mostafahussein opened this issue Apr 14, 2015 · 38 comments
Closed

ImportError: No module named urllib.parse #1288

mostafahussein opened this issue Apr 14, 2015 · 38 comments

Comments

@mostafahussein
Copy link

I am getting this error and don't know what should i do,
I have tried to update six using pip install -U six but its up to date Requirement already up-to-date: six in /usr/lib/python2.7/site-packages
what should i do in order to solve this issue ?

λ - ~ $ python --version
Python 2.7.8
λ - ~ $ docker-compose --version
Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 9, in <module>
    load_entry_point('docker-compose==1.1.0', 'console_scripts', 'docker-compose')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 348, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2311, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2025, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/compose/__init__.py", line 2, in <module>
    from .service import Service  # noqa:flake8
  File "/usr/lib/python2.7/site-packages/compose/service.py", line 10, in <module>
    from docker.errors import APIError
  File "/usr/lib/python2.7/site-packages/docker/__init__.py", line 20, in <module>
    from .client import Client # flake8: noqa
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 34, in <module>
    import websocket
  File "/usr/lib/python2.7/site-packages/websocket/__init__.py", line 22, in <module>
    from ._core import *
  File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 41, in <module>
    from ._url import *
  File "/usr/lib/python2.7/site-packages/websocket/_url.py", line 23, in <module>
    from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse
@dnephin
Copy link

dnephin commented Apr 14, 2015

What if you do pip freeze | grep six ?

I suspect the system installed six is older, the pip install -U only installs a user specific version

@mostafahussein
Copy link
Author

the result of pip freeze | grep six:

λ - ~ $ pip freeze | grep six
six==1.9.0

and according to python package index this is the most recent version

@mostafahussein
Copy link
Author

Is there something i have to do or this is a bug ?!

@dnephin
Copy link

dnephin commented Apr 14, 2015

How did you install compose? I don't think it's a bug in compose, but there may be a missing version restriction somewhere.

Could you try installing it in a virtualenv?

@ghost
Copy link

ghost commented Apr 14, 2015

Same problem here on Fedora 21. I installed with pip for python2.7, is that correct?
/usr/bin/python defaults to python3 however, maybe that is confusing docker-compose?

@mostafahussein
Copy link
Author

@Jonast yes exactly i have the same Linux distribution , i am using Fedora 21, but my python version is 2.7 only

@mostafahussein
Copy link
Author

docker-compose --version just worked now , and i did nothing since i have opened this issue ! , maybe some sort of cache after installation or something!

@gbrennon
Copy link

gbrennon commented May 9, 2015

Same error here, using Fedora 21 and Python 2.7 too

@alejandrodnm
Copy link

@gbrennon I had the same problem and solved it with the solution in #1290 just pip install -U websocket

@bukzor
Copy link

bukzor commented May 29, 2015

The combination of six and requests that docker-compose currently requires causes this error via sys.meta_path hackery if urllib3<1.6 happens to be installed.

Minimal reproduction:

$ virtualenv fresh
New python executable in fresh/bin/python
Installing setuptools, pip...done.

$ source fresh/bin/activate
$ pip install docker-compose
Downloading/unpacking docker-compose
  Downloading docker-compose-1.2.0.tar.gz (57kB): 57kB downloaded
<snip>
Successfully installed docker-compose docopt PyYAML requests texttable websocket-client docker-py dockerpty six backports.ssl-match-hostname argparse
Cleaning up...

$ pip freeze
PyYAML==3.11
argparse==1.3.0
backports.ssl-match-hostname==3.4.0.2
docker-compose==1.2.0
docker-py==1.1.0
dockerpty==0.3.3
docopt==0.6.2
requests==2.5.3
six==1.9.0
texttable==0.8.3
websocket-client==0.31.0
wsgiref==0.1.2

$ cat test.py
import six
print six
print six.__version__

import requests
print requests
print requests.__version__

print six.moves.urllib


$ python test.py
<module 'six' from '/nail/home/buck/fresh/lib/python2.6/site-packages/six.pyc'>
1.9.0
<module 'requests' from '/nail/home/buck/fresh/lib/python2.6/site-packages/requests/__init__.pyc'>
2.5.3
<module 'six.moves.urllib' (built-in)>

$ pip install urllib3'<1.6' --upgrade
Downloading/unpacking urllib3<1.6
  Downloading urllib3-1.5.tar.gz
  Running setup.py (path:/nail/home/buck/fresh/build/urllib3/setup.py) egg_info for package urllib3
Installing collected packages: urllib3
  Running setup.py install for urllib3
Successfully installed urllib3
Cleaning up...

$ python test.py
<module 'six' from '/nail/home/buck/fresh/lib/python2.6/site-packages/six.pyc'>
1.9.0
<module 'requests' from '/nail/home/buck/fresh/lib/python2.6/site-packages/requests/__init__.pyc'>
2.5.3
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print six.moves.urllib
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/six.py", line 90, in __get__
    result = self._resolve()
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/six.py", line 80, in _import_module
    __import__(name)
ImportError: No module named urllib

$ docker-compose --version
Traceback (most recent call last):
  File "/nail/home/buck/fresh/bin/docker-compose", line 9, in <module>
    load_entry_point('docker-compose==1.2.0', 'console_scripts', 'docker-compose')()
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/pkg_resources.py", line 351, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/pkg_resources.py", line 2363, in load_entry_point
    return ep.load()
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/pkg_resources.py", line 2088, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/compose/__init__.py", line 2, in <module>
    from .service import Service  # noqa:flake8
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/compose/service.py", line 10, in <module>
    from docker.errors import APIError
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/docker/__init__.py", line 20, in <module>
    from .client import Client, AutoVersionClient # flake8: noqa
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/docker/client.py", line 35, in <module>
    import websocket
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/websocket/__init__.py", line 22, in <module>
    from ._core import *
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/websocket/_core.py", line 41, in <module>
    from ._url import *
  File "/nail/home/buck/fresh/lib/python2.6/site-packages/websocket/_url.py", line 23, in <module>
    from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse

@dnephin
Copy link

dnephin commented May 30, 2015

Nice find @bukzor . We've updated the requests dependency to requests >= 2.6.1, < 2.7 on master, which is in the 1.3.0 rc1, hopefully that should fix it.

@bukzor
Copy link

bukzor commented Jun 1, 2015

If the purpose of the < is to exclude api-breaking changes, shouldn't <3 be
sufficient?
At the core of it, this bug stems from this unusual practice.

On Sat, May 30, 2015 at 7:23 AM Daniel Nephin notifications@github.com
wrote:

Nice find @bukzor https://github.com/bukzor . We've updated the
requests dependency to requests >= 2.6.1, < 2.7 on master, which is in
the 1.3.0 rc1, hopefully that should fix it.


Reply to this email directly or view it on GitHub
#1288 (comment).

@aanand
Copy link

aanand commented Jun 2, 2015

If the purpose of the < is to exclude api-breaking changes, shouldn't <3 be sufficient?

It should be, but it isn't - if I recall, we've had problems in the past exactly because requests made a breaking change in a minor version release.

@maksymx
Copy link

maksymx commented Jun 8, 2015

Hello,

I also got such error when I've tried to start _bpython_ interpreter. OS: fresh installed Ubuntu 15.04.

Do you guys have any ideas how to fix it?

@bukzor
Copy link

bukzor commented Jun 12, 2015

That's sad.

Things would be better if we'd follow semver more closely.

On Tue, Jun 2, 2015 at 2:59 AM Aanand Prasad notifications@github.com
wrote:

If the purpose of the < is to exclude api-breaking changes, shouldn't <3
be sufficient?

It should be, but it isn't - if I recall, we've had problems in the past exactly
because
requests made a breaking change in a minor version release.


Reply to this email directly or view it on GitHub
#1288 (comment).

@rongnguyen
Copy link

I have the same problem, I am using Fedora 22 and Python 2.7

@rongnguyen
Copy link

ok, I have found the issue. Thanks @bukzor

@dmcgowan
Copy link

Also ran into this issue on Fedora 22 with Python 2.7

running pip install --upgrade websocket worked, is websocket not listed as a dependency?

@aanand
Copy link

aanand commented Jun 20, 2015

Looks like docker-py defines websocket>=0.11.0 on Python 2, so it should have updated when you updated Compose. Do you know what your websocket version was before you upgraded?

@aanand
Copy link

aanand commented Jun 20, 2015

Sorry, meant to link to docker-py's setup.py there: https://github.com/docker/docker-py/blob/1.2.3/setup.py

@lerox
Copy link

lerox commented Jun 22, 2015

I was having:

$ docker-compose --version
Traceback (most recent call last):
  File "/usr/local/bin/docker-compose", line 8, in <module>
    load_entry_point('docker-compose==1.3.1', 'console_scripts', 'docker-compose')()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
    return ep.load()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Python/2.7/site-packages/compose/cli/main.py", line 10, in <module>
    from docker.errors import APIError
  File "/Library/Python/2.7/site-packages/docker/__init__.py", line 20, in <module>
    from .client import Client, AutoVersionClient # flake8: noqa
  File "/Library/Python/2.7/site-packages/docker/client.py", line 37, in <module>
    import websocket
  File "/Library/Python/2.7/site-packages/websocket/__init__.py", line 22, in <module>
    from ._core import *
  File "/Library/Python/2.7/site-packages/websocket/_core.py", line 41, in <module>
    from ._url import *
  File "/Library/Python/2.7/site-packages/websocket/_url.py", line 23, in <module>
    from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse

solved my problem:

$ sudo pip install -U websocket 

@alejandrodnm +1

@ghost
Copy link

ghost commented Sep 6, 2015

This is still happening on new Fedora 22 installs. Is this a pip bug? Why is an explicit "sudo pip install -U websocket" necessary to get docker-compose running properly? (I did install docker-compose through pip after all, so you'd expect it to do that during install of the deps on its own)

@KrE80r
Copy link

KrE80r commented Sep 22, 2015

in my case i had to install python-devel (fedora 21)
then
pip install websocket

@jacek99
Copy link

jacek99 commented Sep 29, 2015

Sorry, still getting this on Fedora 22.
Just tried to install it from the fedora repos, it cannot even show the version number

sudo dnf install docker-compose

docker-compose --version
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 9, in
load_entry_point('docker-compose==1.2.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2361, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python2.7/site-packages/compose/init.py", line 2, in
from .service import Service # noqa:flake8
File "/usr/lib/python2.7/site-packages/compose/service.py", line 10, in
from docker.errors import APIError
File "/usr/lib/python2.7/site-packages/docker/init.py", line 20, in
from .client import Client, AutoVersionClient # flake8: noqa
File "/usr/lib/python2.7/site-packages/docker/client.py", line 35, in
import websocket
File "/usr/lib/python2.7/site-packages/websocket/init.py", line 22, in
from ._core import *
File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 41, in
from ._url import *
File "/usr/lib/python2.7/site-packages/websocket/_url.py", line 23, in
from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse

I already have websocket and upgraded it via

sudo pip install --upgrade websocket

@jacobtomlinson
Copy link

Same issue on CentOS 7.0.1406.

[root@api ~]# docker-compose --version
Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 9, in <module>
    load_entry_point('docker-compose==1.4.2', 'console_scripts', 'docker-compose')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 10, in <module>
    from docker.errors import APIError
  File "/usr/lib/python2.7/site-packages/docker/__init__.py", line 20, in <module>
    from .client import Client, AutoVersionClient # flake8: noqa
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 23, in <module>
    from . import clientbase
  File "/usr/lib/python2.7/site-packages/docker/clientbase.py", line 7, in <module>
    import websocket
  File "/usr/lib/python2.7/site-packages/websocket/__init__.py", line 22, in <module>
    from ._core import *
  File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 41, in <module>
    from ._url import *
  File "/usr/lib/python2.7/site-packages/websocket/_url.py", line 23, in <module>
    from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse

websocket did not resolve for me.

@jacobtomlinson
Copy link

Using a virtualenv worked for me as stated in the documentation.

$ pip install virtualenv
$ virtualenv venv
$ source venv/bin/activate
(venv) $ pip install docker-compose
(venv) $ docker-compose --version
docker-compose version: 1.4.2

@jacek99
Copy link

jacek99 commented Oct 21, 2015

This is not really an acceptable solution.

For example, in Fedora, I install docker from the system packages. If I have to install it using virtualenv from pip, the versions of compose and docker may be off and things don't work (had that happen when I tried to mix and match the two).

Docker Compose should not be so brittle as to require such setup. Remember that most developers using this will have little or no knowledge of Python so all of this is just an extra hill for them to climb....

We've actually abandoned compose adoption because so many folks had issues installing it. Had to roll everything using basic shell scripts instead.

@dnephin
Copy link

dnephin commented Oct 21, 2015

@jacek99

  1. This is not something that can be fixed by compose. Every linux distro has different versions of these system packages, and they're often packed differently which causes bugs like the one described in this issue. If you do a google search for this error you're find many results for other tools that have the same problem.
  2. pip is not the recommended install option for this reason. We provide binaries for linux so you don't have to pip install. We now have master builds as well (https://dl.bintray.com/docker-compose/master/)
  3. If you must use pip, virtualenv is the best way to ensure that you're not conflicting with system packages.

Did you try installing the pre-built binaries?
Are you aware that you can set https://github.com/docker/compose/blob/master/docs/reference/overview.md#compose_api_version to make compose work with older docker versions?

Installing with pip doesn't really have anything to do with the docker api version mismatch. We always support the last two versions of the docker api.

@jacek99
Copy link

jacek99 commented Oct 21, 2015

Personally, I feel like rewriting it in Go and having all deps built-in would make this easier. Since the rest of Docker is in Go would that not make more long term sense?

Proper Linux patterns are to use the libs in your distro repos, not to download custom one-off versions that do not get upgraded automatically.

@dnephin
Copy link

dnephin commented Oct 21, 2015

Rewriting in go is a pretty heavy handed way to solve this problem. Downloading a binary seems to be the convention with go packages as well, so rewriting it doesn't actually solve the problem. It sounds like what you want is an rpm/deb install option. I personally think that would be a good idea. Would you mind creating an issue for that?

@jacek99
Copy link

jacek99 commented Oct 21, 2015

That is what I have been trying to do on Fedora:

dnf install docker docker-compose

and then

docker-compose -v
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 9, in
load_entry_point('docker-compose==1.2.0', 'console_scripts', 'docker-compose')()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2355, in load
return self.resolve()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2361, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python2.7/site-packages/compose/init.py", line 2, in
from .service import Service # noqa:flake8
File "/usr/lib/python2.7/site-packages/compose/service.py", line 10, in
from docker.errors import APIError
File "/usr/lib/python2.7/site-packages/docker/init.py", line 20, in
from .client import Client, AutoVersionClient # flake8: noqa
File "/usr/lib/python2.7/site-packages/docker/client.py", line 35, in
import websocket
File "/usr/lib/python2.7/site-packages/websocket/init.py", line 22, in
from ._core import *
File "/usr/lib/python2.7/site-packages/websocket/_core.py", line 41, in
from ._url import *
File "/usr/lib/python2.7/site-packages/websocket/_url.py", line 23, in
from six.moves.urllib.parse import urlparse
ImportError: No module named urllib.parse

because any version of the Python library can be easily overriden if someone uses pip to install something outside of the system repos (which I have done).

It just makes docker-compose very fragile compared to other parts of Docker.

I have seen quite a few issues reported here from folks who have difficulty installing compose with exactly similar issues.

I tried playing with library versions, removing via pip (python-requests), reinstalling the system ones, etc. Still issues like this persist.

@dnephin
Copy link

dnephin commented Oct 21, 2015

I think even with a deb/rpm the right way to do this is a virtualenv. Debian packages have https://github.com/spotify/dh-virtualenv which install all the dependencies in a virtualenv within the package. I don't know of a similar tool for rpms, but I think it should be possible still.

@dnephin
Copy link

dnephin commented Oct 21, 2015

I created #2235

@ovntatar
Copy link

I solved issue on my CentOS Linux release 7.1.1503 (Core) by running following commands:

pip install pyopenssl ndg-httpsclient pyasn1
pip install --upgrade urllib3
pip freeze | grep urllib
urllib3==1.12

pip uninstall six
pip install six
pip install --upgrade six

@caruccio
Copy link

caruccio commented Nov 4, 2015

@ovntatar +1

@tareqalam
Copy link

running this command fixed things for me:
sudo pip install -U future

@harimau99
Copy link

@ovntatar +1
work like charm

@harimau99
Copy link

running this command fixed things for me:
sudo pip install -U future

what does this mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests