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.
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.6.40898
Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.
subprocess.call() throws error «FileNotFoundError: [Errno 2] No such file or directory» when redirecting stdout to file
I want to redirect the console output to a textfile for further inspection. The task is to extract TIFF-TAGs from a raster file (TIFF) and filter the results. In order to achieve this, I have several tools at hand. Some of them are not python libraries, but command-line tools, such as «identify» of ImageMagick.
My example command-string passed to subprocess.check_call() was:
Here, in the output of the TIFF-TAGs produced by «identify» all lines which contain information about the TAG number «274» shall be either displayed in the console, or written to a file.
Error-type 1: Displaying in the console
Error-type 2: Redirecting the output to textfile
These subprocess.check_call() functions were executed by the following convenience function:
EDIT:
For more security, the piping-process should be split up as mentioned in the following, but this didn’t really work out for me. If you have an explanation for why a split-up piping process like
doesn’t produce the output-textfile while still exiting successfully, I’d be delighted to learn about the reasons.
OS and Python versions
NAME=»Ubuntu» VERSION=»18.04.3 LTS (Bionic Beaver)» ID=ubuntu ID_LIKE=debian PRETTY_NAME=»Ubuntu 18.04.3 LTS» VERSION_ID=»18.04″
Python 3.7.6 (default, Jan 8 2020, 19:59:22) [GCC 7.3.0] :: Anaconda, Inc. on linux
2 Answers 2
As for the initial error mentioned in the question: The comments answered it with that I needed to put in all calls of subprocess.check_call() the kwarg shell=True if I wanted to pass on a prepared shell-command string like
As a sidenote, I noticed that it doesn’t make a difference if I enquote the paths or not. I’m not sure whether it makes a difference using single (‘) or double («) quotes.
Furthermore, for the sake of security outlined in the comments to my questions, I followed the docs about piping savely avoiding shell and consequently changed from my previous standard approach
to the (somewhat cumbersome) piping steps delineated hereafter:
Yet in spite of all these apparent improvements, there is no output textfile generated, albeit the process seemingly doesn’t produce any errors and finishes «correctly» after the last line of the piping process:
As a consequence, I’m still forced to use the old and unsecure, but at least well-working approach via the shell:
At least it works now employing this former approach, even though I didn’t manage to implement the more secure piping procedure where several commands can be glued/piped together.
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.6.40898
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.











