Reputation: 336
I have this line in my script:
from path import Path
but I ran into this error
ImportError: No module named path
however, I have install path.py in my system, there is no problem when I write in python3 with from path import Path
in terminal. this is very weird.
Upvotes: 9
Views: 30113
Reputation: 3791
This is somehow funny. But sometimes when you have copied a code from SO or other places, they use this as an illustrative example: path.to.yourpackage
. For example mine was
DATABASE_ROUTERS = ['path.to.DatabaseRouter']
So in these cases it's obvious there is no module named 'path'. But you rushed when copying it and forgot fixing it. Posted this so that it helps someone else who may encounter this.
Upvotes: 0
Reputation: 369274
If you mean Path
in standard library, use pathlib.Path
, not path.Path
.
>>> from pathlib import Path
>>> Path
<class 'pathlib.Path'>
Upvotes: 5