Filenotfounderror no such file or directory pygame что делать
pygame.error: /etc/timidity.cfg: No such file or directory #343
Comments
japrogramer commented Jul 20, 2017 •
Hello im getting an error when using timidity++ with pygame
pygame.error: /etc/timidity.cfg: No such file or directory
The text was updated successfully, but these errors were encountered:
japrogramer commented Jul 20, 2017
takluyver commented Jul 22, 2017
Is there a traceback associated with that error?
japrogramer commented Jul 24, 2017 •
I was trying to play a midi file, cant remeber exactly how. after i made the link between the files the error went away but no sound played. i was running the code from jupyter notebook.
neither the host nor client played music.
pygame.error: /etc/timidity.cfg: No such file or directory
takluyver commented Jul 25, 2017
When you get an error from Python code, it usually displays a ‘traceback’, which shows what functions were running when the problem happened. It might be quite long, depending on the code involved. It will be a series of chunks like this:
The error message is usually displayed at the bottom of this.
If you get a traceback, it’s really important info for debugging, so it’s a good thing to include in bug reports. If there isn’t one for some reason, that’s OK, but hopefully that’s unusual. 🙂
adicarlo commented Sep 21, 2017
Its not clear to me this is really a pygame bug. I can’t see anywhere in the sources where the path to the config file is hardcoded.
takluyver commented Sep 22, 2017
cid0rz commented Feb 4, 2018
Hello all, I am also using jupyter to work with music21 musicological analysis tool. I tried to play before installing pygame and it complained it needed pygame. So I installed. I’m in pytjon 3.6 on Xenial and i try this example taken from here:
Python FileNotFoundError: [Errno 2] No such file or directory Solution
In most cases, any file you reference in a Python program needs to exist. This is, of course, unless you are creating a new file and writing to it. If you reference a file that does not exist, Python will return an error. One type of error is the FileNotFoundError, which is raised when referencing a file that does not exist using the os library.
- Career Karma matches you with top tech bootcamps Get exclusive scholarships and prep courses
- Career Karma matches you with top tech bootcamps Get exclusive scholarships and prep courses
In this guide, we’re going to walk you through what the FileNotFoundError: [Errno 2] No such file or directory error means and how you can solve it in your code. Without further ado, let’s begin.
Python FileNotFoundError: [Errno 2] No such file or directory
Any message with the contents FileNotFoundError indicates that Python cannot find the file you are referencing. Python raises this error because your program cannot continue running without being able to access the file to which your program refers.
This error is usually raised when you use the os library. You will see an IOError if you try to read or write to a file that does not exist using an open() statement.
Let’s take a look at an example scenario featuring a FileNotFoundError message.
An Example Scenario
We’re writing a program that lists all the files in a folder. The folder we are referencing contains a list of markdown documentation for our project. To start, let’s import the os library, which has a method that lets us see all the files in a folder:
Next, we are going to use the os.listdir() method to get a list of the files in our folder:
We retrieve a list of the files in the “/home/james/python_error/documentation/” folder. The for statement iterates over each file that the os.listdir() method finds. We print the name of each file to the console. Let’s see what happens when we run our code:
81% of participants stated they felt more confident about their tech job prospects after attending a bootcamp. Get matched to a bootcamp today.
Find Your Bootcamp Match
The average bootcamp grad spent less than six months in career transition, from starting a bootcamp to finding their first job.
Start your career switch today
Our code does not work.
The Solution
We have referenced a folder that does not exist. To solve the error in our program, we must make sure the directory to which we point exists. The actual folder with our docs is at /home/james/python_error/docs. Let’s change the folder to which our program refers to the one that actually contains our documentation:
The output from our command is what we expected. We can see there is one file in our folder. If we had other files in the /home/james/python_error/docs/ folder, we would be able to see them in the output of our program.
Conclusion
The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check that you are referring to the right file or folder in your program.
Now you have the knowledge you need to successfully fix this Python error.
Ошибка в программном коде, на python
Ошибка в коде на python! Сайт с которого я брал код! https://tokmakov.msk.ru/blog/item/60
Я понял что ошибка в этом! file = open(‘C:\\example\\tinko.txt’, mode = ‘w’, encoding = ‘utf-8’) у меня нету такого файла на ПК! Что делать?
что выдаёт;
Traceback (most recent call last):
File «C:/Users/one-h/PycharmProjects/pythonProject/rwrf.py», line 9, in
file = open(‘C:\\example\\tinko.txt’, mode = ‘w’, encoding = ‘utf-8’)
FileNotFoundError: [Errno 2] No such file or directory: ‘C:\\example\\tinko.txt’
и ещё
pydev debugger: process 3016 is connecting
Connected to pydev debugger (build 202.6397.98)
Traceback (most recent call last):
File «C:\Program Files\JetBrains\PyCharm 2020.2\plugins\python\helpers\pydev\pydevd.py», line 1448, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File «C:\Program Files\JetBrains\PyCharm 2020.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py», line 18, in execfile
exec(compile(contents+»\n», file, ‘exec’), glob, loc)
File «C:/Users/one-h/PycharmProjects/pythonProject/rwrf.py», line 9, in
file = open(‘C:\\example\\tinko.txt’, mode = ‘w’, encoding = ‘utf-8’)
FileNotFoundError: [Errno 2] No such file or directory: ‘C:\\example\\tinko.txt’
Как вы беретесь программировать, не зная ЭЛЕМЕНТАРНОГО?!
при открытии на запись, файл создаётся автоматически (или перезаписывается). Эта ошибка означает, что не существуют эти папки.
Перед открытием файлов лучше проверять и создавать нужные пути:
Python FileNotFoundError: [Errno 2] No such file or directory:
I am trying to open all the ‘*.json’ files in a directory and get some data out of them
This is the Error i get :
3 Answers 3
You are running the script in different path. Adding the absolute path of the filename will do the trick.
replace line with open(filename,’r’) as f: with with open(os.path.abspath(filename),’r’) as f:
If you want Python to find within the given path, you should write somthin like :
Not the answer you’re looking for? Browse other questions tagged python or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.3.40888
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
FileNotFoundError: [Errno 2] No such file or directory: Python
FileNotFoundError: [Errno 2] No such file or directory: выходит после того как я пытаюсь открыть файл.
Тут я запускаю скрипт с меин файла скрин https://prnt.sc/vm8psi
Дальше этот меин файл запускает скрипт но сначала записывает данные в файл.
После чего в скрипте происходит следущее
Скрипт находитса в данной директории https://prnt.sc/vm8s9a
А файл в который я записываю данные находитса в https://prnt.sc/vm8sya
Эту функцию я вызываю в отдельном потоке.
1 ответ 1
Файл не находится, потому, что не там ищете. Проверьте перед вызовом open что вернет os.getcwd() в обоих случаях. Очевидно, что в программе неправильные предположения о текущем рабочем каталоге. Либо используйте полный путь либо по другому синхронизируйте место записи и чтения.
Всё ещё ищете ответ? Посмотрите другие вопросы с метками python или задайте свой вопрос.
Похожие
Подписаться на ленту
Для подписки на ленту скопируйте и вставьте эту ссылку в вашу программу для чтения RSS.
дизайн сайта / логотип © 2021 Stack Exchange Inc; материалы пользователей предоставляются на условиях лицензии cc by-sa. rev 2021.12.3.40888
Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.






