PQuix
PQuix

Reputation: 83

ImportError: No module named parse - Python 3

When I try to run pipenv run main.py I am met with the error ImportError: No module named parse.

I've looked around online but all I can find are people not using the correct python version, but I don't think that is the case here.

I first run pipenv --three to build the virtualenv using python 3.6.6. After that succeeds I am met with the previously stated error.

In my __init.py__ file I'm importing parse through from urllib.parse import urlparse. The threads I can find online about the subject seems to be people using the Python 2 import syntax, but that's not the case here as far as I can tell.

Any help would be greatly appreciated...

Upvotes: 1

Views: 2279

Answers (1)

Frederik Bode
Frederik Bode

Reputation: 2744

The problem is that you are only importing that one function urlparse, not the entire package urllib.parse, so you don't have access to that yet. If you need the entire package you should import it with from urllib import parse.

You can also change from urllib.parse import urlparse to from urllib.parse import urlparse as parse if you only need the method, but then you would have clashing name (parse the module and parse the function). This works fine, as you can only access the function parse anyway, but this might get confusing later when you do need the entire package.

Upvotes: 1

Related Questions