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
Question Cannot import easysnmp: ImportError: libnetsnmp.so.30 Calab 4 999 Jun-08-2023, 08:52 PM
Last Post: Gribouillis
  Import a module one step back of the path prathampatel9 1 1,035 Sep-21-2022, 01:34 PM
Last Post: snippsat
  ImportError: cannot import name 'Pyfhel' from 'Pyfhel' Anldra12 9 3,443 Dec-13-2021, 06:55 PM
Last Post: Anldra12
  ImportError: cannot import name 'get_config' russray2008 0 4,678 Sep-20-2021, 02:18 PM
Last Post: russray2008
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,148 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  'import Path' do not understand how to use it tester_V 2 1,601 Jun-19-2021, 02:23 AM
Last Post: tester_V
  ImportError: cannot import name 'Union' from '_ctypes' (unknown location) ciuffoly 15 10,260 Oct-09-2020, 06:58 AM
Last Post: ciuffoly
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 3,859 Jun-18-2020, 08:07 AM
Last Post: buran
  ImportError: cannot import name 'MidiEvaluator' from 'parser' (Windows 10) spiffspaceman 4 2,630 May-22-2020, 10:16 PM
Last Post: snippsat
  ImportError: cannot import name 'X ' from ' Y' (Unknown location) Arjunpi 1 4,318 Apr-30-2020, 12:56 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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