Python Forum
ImportError: cannot import name 'path'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError: cannot import name 'path'
#1
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!!!
Reply
#2
Try to import os.
See my tread...https://python-forum.io/Thread-Looping-through-music-files
Reply
#3
using pathlib see https://stackoverflow.com/a/43430592
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ImportError: cannot import name 'NullHandler' from 'logging' sukanta80 0 630 Jul-28-2025, 03:26 PM
Last Post: sukanta80
  ImportError: cannot import name 'Pyfhel' from 'Pyfhel' Anldra12 11 8,146 Jun-16-2025, 07:08 AM
Last Post: ItsTheGoose
  import a function from another file using relative path paul18fr 6 10,448 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  ImportError: cannot import name 'scipy_namespace_for' from 'scipy._lib._array_api' AgileAVS 0 3,963 Jul-15-2024, 08:45 AM
Last Post: AgileAVS
Question Cannot import easysnmp: ImportError: libnetsnmp.so.30 Calab 4 3,142 Jun-08-2023, 08:52 PM
Last Post: Gribouillis
  Import a module one step back of the path prathampatel9 1 2,609 Sep-21-2022, 01:34 PM
Last Post: snippsat
  ImportError: cannot import name 'get_config' russray2008 0 7,242 Sep-20-2021, 02:18 PM
Last Post: russray2008
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 4,149 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  'import Path' do not understand how to use it tester_V 2 3,265 Jun-19-2021, 02:23 AM
Last Post: tester_V
  ImportError: cannot import name 'Union' from '_ctypes' (unknown location) ciuffoly 15 15,900 Oct-09-2020, 06:58 AM
Last Post: ciuffoly

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020