Running Python 3.9.6 on Terminal (Mac).
I can't seem to figure out how to use an existing file from the python console.
My existing file is named sim.txt.
>>> wv.evaluate_word_pairs("sim.txt")
Gets me FileNotFoundError: [Errno 2] No such file or directory: 'sim.txt'.
How do I get this to work?
Related
why spyder code editor gives us error when we make another file in it.error?
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Pouria/untitled0.py'.
how to solve it?
I'm trying to run a .ipynb file from a gitlab repo on jupyternotebook. I got the error FileNotFoundError: [Errno 2] No such file or directory: 'data/train.tsv' so I figured that python is looking for the .tsv file in the wrong directory so in order to solve this I have to find where the .tsv file is first, but I can't find the file anywhere in the repo. Not sure if I'm understanding this error correctly.
Here is the full traceback
I've encountered a very bizarre error when trying to write files with python. As of today, whenever I try and open a file in write mode, python throws the error 'No such file or directory', even if the directory definitely exists. All other python functionality seems to be working, including reading files.
A simple example of the problem, when run using the command line from my documents:
>>> with open('test.csv', 'w') as f:
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'test.csv'
I'm using a windows 10 machine, python 3.7, with conda environments specific to projects I'm working on.
I have tried:
Restarting
Creating a clean conda environment (conda create --name test python=3.7)
Running in base without a conda environment
Providing the path as an absolute rather than relative, i.e. C:/Users/<myname>/Documents/test.csv
Trying to run this in other directories
The only success I've had is when running the code with append mode. If I try and create a file as above using mode='a' it throws the error, however if I manually create an empty file, I can append into it.
I really have no idea how to resolve this, other than to completely remove anaconda and python and re-install.
try declare a variable for the file before 'with' statement:
file = open('test.csv', 'w')
with file as f:
# your code here
I am quite new to Python and I am having problems opening a file in Python.
I want to open a text file called 'coolStuff' in a Folder on my Desktop and this is how I type in the command but I still get an error message. The file exists and so I do not understand why I get that error message.
open("coolStuff.txt","r")
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
open("coolStuff.txt","r")
FileNotFoundError: [Errno 2] No such file or directory: 'coolStuff.txt'
If you want to simply supply a filename like coolStuff.txt without also providing a full directory, then you have to make sure that Python is running in the same directory as the file. If you aren't sure what directory Python is running in, try this:
import os
print(os.getcwd())
You have two options:
let's say your file is in C:\path\to\dir\coolStuff.txt
1.
open(r'C:\path\to\dir\coolStuff.txt','r')
2.
import os
os.chdir(r'c:\path\to\dir')
open('coolStuff.txt', 'r')
Because the file you want to open is not in the current directory.You can find the file 'coolStuff.txt' in the terminal and launch your python environment at the same directory.
My lab used python 2.7 with pygame with a program and I'm trying to run it on my computer with no success. Things I've tried:
(1) Installing Python 2.7 and pygame on Windows 10. The program just crashes when I run it with IDLE.
(2) Running a virtual system with ubuntu and installing IDLE, Python 2.7, pygame, etc.
(a) If I open IDLE and open the file Output.py
(b) If I open a shell and type
python /home/frank/Dropbox/clab/Maze_2.2/Output.py
Then I get the following error
python /home/frank/Dropbox/clab/Maze_2.2/Output.py Traceback (most
recent call last):
File "/home/frank/Dropbox/clab/Maze_2.2/Output.py", line 11, in
from Output2d import *
File "/home/frank/Dropbox/clab/Maze_2.2/Output2d.py", line 8, in
import ReadFile
File "/home/frank/Dropbox/clab/Maze_2.2/ReadFile.py", line 44, in
print get_mins()
File "/home/frank/Dropbox/clab/Maze_2.2/ReadFile.py", line 37, in
get_mins handle = open(INPUT_FILE, 'r')
IOError: [Errno 2] No such file or directory: 'data/prob.txt'
The file prob.txt is present and is not corrupt so I'm really unsure what to do next to troubleshoot this issue
This is not a pygame issue, you are just missing some data files of the game Maze: Maze_2.2/data/*
A file named data/prob.txt, you should find it