Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import pathlib

Whenever I write:

import pathlib 

or

from pathlib import path 

I got this:

ImportError: No module named pathlib

I tried also naming it os.path.

I'm on Python 2.7.14

Is pathlib in Python 2 or only in 3? If it's not available, what else can I use?

like image 808
Nonox Avatar asked Apr 08 '18 17:04

Nonox


People also ask

How do I fix No module named Pathlib?

Upgrading the Python Version to ( 3.4 +)- Hence we can upgrade our python version from Python 2 to Python 3. This is the most easy way to fix this error no module name pathlib.

Is Pathlib available in Python 2?

Python 3.2 or later is recommended, but pathlib is also usable with Python 2.7 and 2.6.

Is Pathlib included in Python?

The pathlib library is included in all versions of python >= 3.4.

Is Pathlib path PathLike?

pathlib. Path (WindowsPath, PosixPath, etc.) objects are not considered PathLike : PY-30747.


1 Answers

You may install library pathlib2 by the following command:

pip install pathlib2

After that, your import should work:

import pathlib2 as pathlib

If you want to use just standard modules, usage of os.path is also possible, but it has another functions and working differently.

like image 176
Ada Lovelace Avatar answered Sep 16 '22 16:09

Ada Lovelace