Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named path

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.

like image 964
Shining Zhong Avatar asked Dec 19 '17 16:12

Shining Zhong


People also ask

How do I resolve ImportError no module name?

To get rid of this error “ImportError: No module named”, you just need to create __init__.py in the appropriate directory and everything will work fine.

How do I fix the ImportError in Python?

Python's ImportError ( ModuleNotFoundError ) indicates that you tried to import a module that Python doesn't find. It can usually be eliminated by adding a file named __init__.py to the directory and then adding this directory to $PYTHONPATH .

What is SYS path Python?

sys. path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module. When a module(a module is a python file) is imported within a Python file, the interpreter first searches for the specified module among its built-in modules.

What is import error in Python?

In Python, ImportError occurs when the Python program tries to import module which does not exist in the private table. This exception can be avoided using exception handling using try and except blocks. We also saw examples of how the ImportError occurs and how it is handled.


1 Answers

If you mean Path in standard library, use pathlib.Path, not path.Path.

>>> from pathlib import Path
>>> Path
<class 'pathlib.Path'>
like image 146
falsetru Avatar answered Oct 07 '22 17:10

falsetru