ImportError: No module named pathlib

Viewed 30635

I have the following when I run pip list - I am on 2.7 over mac os:

➜ python --version   
Python 2.7.10



➜ pip list        
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package            Version
------------------ -------
pathlib            1.0.1  
pip                19.0.2 
python-http-client 3.2.7  
setuptools         40.8.0 
wheel              0.33.0 

Now in my code I have:

from pathlib import Path

and when I run from command line I get:

Traceback (most recent call last):
  File "testexe.py", line 7, in <module>
    from pathlib import Path
ImportError: No module named pathlib
2 Answers

You can install a backwards compatible version of the current pathlib library from PyPI here: pathlib2

The original pathlib library is not maintained anymore. I'm not sure why it would but perhaps that's affecting your import ¯_(ツ)_/¯

You should use Python 3 unless you absolutely have to use Python 2. The pathlib module has been included as part of the standard library since Python 3.4. So while it might be annoying to swap, at least your pathlib import will work!

You are using pip from Python2 consider migrating to Python3

for future installs use

pip3 install -r requirements.txt
Related