Please check your current directory.

For that just do this:

import os
print (os.getcwd())
Answer from Roman Belousov on Stack Overflow
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ questions โ€บ python-can-t-find-local-files-modules
Python can't find local files/modules | DigitalOcean
February 1, 2020 - When running the app inside a virtualenv and trying to run the application using python3.7 application.py I get the following error message: Traceback (most recent call last): File "application.py", line 11, in <module> from config import * ModuleNotFoundError: No module named 'config' What puzzles me is that config.py is located in the same folder as application.py, and not in a subfolder. I have duplicated the setup on my local machine, also running Python 3.7 and inside a virtualenv, and the importing (and the app) works flawlessly.
Discussions

Python script can't find file, even though they are in the same folder?
Often when this problem comes up it's because the user is using Windows, which hides the file extension. Use this code to print out the true names of all the files in the folder import os print(os.listdir('.')) And check to make sure the name you are using matches exactly. More on reddit.com
๐ŸŒ r/learnpython
3
3
November 8, 2017
Python can't find module in the same folder - Stack Overflow
My python somehow can't find any modules in the same directory. What am I doing wrong? (python2.7) So I have one directory '2014_07_13_test', with two files in it: ... >>> Traceback (most recent call last): File "", line 1, in File "", line 4, in ImportError: No module named hello ... @Casy_fill Do you run your program from the directory, where are the files present? For importing, it does not ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python not finding file on local desktop - Stack Overflow
I have a simple python script that determines whether a file called test.csv is on my desktop or not. I have the file on my desktop, but the script always says it doesn't exit. I've done some res... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python doesn't find local module although it is installed and its location exists in sys.path
I installed a local module using the pyproject.toml approach by following the great tutorial by RealPython: Packaging Your Python Code With pyproject.toml | Complete Code Conversation - YouTube Although the module seems to be locally installed, I am unable to invoke it from outside the project ... More on discuss.python.org
๐ŸŒ discuss.python.org
6
0
March 23, 2023
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Directory not found - Python Help - Discussions on Python.org
March 11, 2023 - I am getting this error: `C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\python.exe: canโ€™t open file โ€˜C:\Users\Anthony.DESKTOP-ES5HL78\04_02.pyโ€™: [Errno 2] No such file or directoryโ€™ I am sure โ€ฆ
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Python doesn't find local module although it is installed and its location exists in sys.path - Python Help - Discussions on Python.org
March 23, 2023 - I installed a local module using the pyproject.toml approach by following the great tutorial by RealPython: Packaging Your Python Code With pyproject.toml | Complete Code Conversation - YouTube Although the module seems to be locally installed, I am unable to invoke it from outside the project directory.
Find elsewhere
๐ŸŒ
PythonAnywhere
help.pythonanywhere.com โ€บ pages โ€บ NoSuchFileOrDirectory
No such file or Directory? | PythonAnywhere Help
December 17, 2016 - code like this, based on deriving the current path from Python's magic __file__ variable, will work both locally and on the server, both on Windows and on Linux... One other thing that might be going on is that you're using the wRoNG cAsINg. Casing doesn't matter on Windows but it does on Linux (and therefore, it matters on PythonAnywhere).
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ "file not found" error, but both files are in the same directory.
r/learnpython on Reddit: "File not found" error, but both files are in the same directory.
September 15, 2023 -

Hi,

I'm working on an exercise from Python Crash Course, and I'm getting this error, even though both my program file and the read file are in the same directory/folder: FileNotFoundError: [Errno 2] No such file or directory: 'learning_python.txt'

This is the code i'm running:

from pathlib import Path

print("--- Reading in the entire file:")

path = Path('learning_python.txt')

contents = path.read_text()

print(contents)

print("\n--- Looping over the lines:")

lines = contents.splitlines()

for line in lines:

print(line)

I'm only getting the error when I run the program on VS Code, when I run it in Sublime Text the program runs with no issues.

Does anyone have any suggestions on what might be the problem and how to fix it?

Thanks in advance.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ python can't find file in the same directory
python can't find file in the same directory : r/learnpython
May 19, 2021 - Non-absolute paths are relative to the working directory, not the file location. ... What apps can i use to write python?
๐ŸŒ
GitHub
bic-berkeley.github.io โ€บ psych-214-fall-2016 โ€บ sys_path.html
Where does Python look for modules? โ€” Functional MRI methods
When Python hits the line import a_module, it tries to find a package or a module called a_module. A package is a directory containing modules, but we will only consider modules for now. A module is a file with a matching extension, such as .py. So, Python is looking for a file a_module.py, and not finding it.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
My program is not finding another file - Python Help - Discussions on Python.org
May 13, 2024 - The following code has a problem: #! /usr/bin/env python3 # -*- coding: utf-8 -*- # # GUI module generated by PAGE version 8.0 # in conjunction with Tcl version 8.6 # May 11, 2024 01:17:29 PM BST platform: Darwin import sys import tkinter as tk import tkinter.ttk as ttk from tkinter.constants import * import os.path _location = os.path.dirname(__file__) import LoginForm_support The last line is the problem.
๐ŸŒ
McNeel Forum
discourse.mcneel.com โ€บ scripting
Python not able to find existing file? - Scripting - McNeel Forum
January 6, 2021 - Hello all, I have a whole load of files where a particular layer has to be deleted and placed into a new folder as a DXF. The odd thing is I had it working perfectly earlier however when I went back to run it I noticed the command line was full of errors saying the file could not be found, but stranger than that, a copy of all my files were made in the destination folder and the desired files with the removed layers were left in the origin folder.
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ fopp โ€บ Files โ€บ FindingaFileonyourDisk.html
10.5. Finding a File in your Filesystem โ€” Foundations of Python Programming
If your file and your Python program are in different directories, however, then you need to specify a path. You can think of the filename as the short name for a file, and the path as the full name. Typically, you will specify a relative file path, which says where to find the file to open, relative to the directory where the code is running from.
๐ŸŒ
Quentin Fortier
fortierq.github.io โ€บ python-import
How to import local modules with Python - Quentin Fortier
May 9, 2021 - A better solution would be to use a context.py file modifying sys.pathand imported by every other file, but this is still unsatisfying. Another possibility is to add the root directory to PYTHONPATH (before running the script).