Python Forum
ImportError: cannot import name 'path' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ImportError: cannot import name 'path' (/thread-19768.html)



ImportError: cannot import name 'path' - user123 - Jul-13-2019

Hi All,

I've written a small piece of code to get the number of files in a directory.
I installed the path module as well, but still i'm getting the error :

ImportError: cannot import name 'path' while running the code.

Code:
root@Anon:# cat cleanup.py 
#!/usr/bin/python3


from path import path
d=('/home/us3r/sample/')
num_files=len(d.files())
print(num_files)
I'm executing the code from the Linux terminal as below:

./cleanup.py

Thanks in Advance!!!


RE: ImportError: cannot import name 'path' - ebolisa - Jul-13-2019

Try to import os.
See my tread...https://python-forum.io/Thread-Looping-through-music-files


RE: ImportError: cannot import name 'path' - Larz60+ - Jul-14-2019

using pathlib see https://stackoverflow.com/a/43430592