i want try to deploy one little browser application. (it's only a button that do nothing). When I try to debug and run my app with emrun, I receive:
C:\Users\Acer\AppData\Local\Programs\Python\Python39\python.exe: can't open file 'C:\.py': [Errno 2] No such file or directory
I had understand that ".py" is missing but I don't know how to fix it.
I'm using window 10.
The path to the file is wrong
It tries to open the file in the dir 'C:' what is not correct.
Change the file to the dir where the file is saved.
Related
So basically the file is on the desktop/pythonBot folder, but the cmd cant open it up? The code I type in is python bot.py. I followed this dude's guide here:
https://www.smartspate.com/how-to-create-a-telegram-bot-with-ai-in-30-lines-of-code-in-python/
(Sorry I am just a senior high student with no coding background)
From screenshot i guessed you have .py in another directory.
cmd is searching for "bot.py" file in C:\Users\s9800 directory.From error i can guess your bot.py file is in another direcotry.Provide full of .py file
How to run .py file
1st way :open cmd,drag and drop .py file to cmd and press enter
2nd way:Go to directory where your .py file is.Wrtie "cmd" in address bar ,it will open cmd ,type file name and press enter.
It looks like you are not in the correct directory, us cd to navigate to desktop/pythonBot or alternatively, use the full path when running the file.
I have a small enough Python project in Eclipse Neon and keep getting the same error and can't find proper documentation on how to solve. In my main I need to call a file that is located in another folder. The error I receive is IOError: [Errno 2] No such file or directory:
I have an empty init.py file in the folder (XML_TXT) that I'm trying to use.
It looks like Groovy is importing okay, or else you would get an ImportError. An IOError indicates that it can't find "test.txt". Does that file exist?
It will work if the file path is relative to where you are running the script from. So for example if test.txt is in a folder
Groovy("folder_name/test.txt")
You can also go up in the directory structure if you need to, for example
Groovy("../folder_name/test.txt")
Or, if you want to be able to run the file from anywhere, you can have python work out the absolute path of the file for you.
import os
filename = os.path.join(os.path.dirname(__file__), 'folder_name/test.txt')
u = Groovy(filename)
I want to use some text files that I have in the same directory in my script. But Atom always gives me this error
FileNotFoundError: [Errno 2] No such file or directory: 'comments.txt'
[Finished in 0.156s]
Anyone know how to fix this?
This is my code
with open('comments.txt', 'r') as f:
myNames = [line.strip() for line in f]
print(myNames)
It works on other IDE's such as Pycharm and sublime text. I also tried it on the python idle.
In Atom, it only works when I give it the full path. But I want it to only use the project path.
If you are using the Script package, go to File>Settings (or CTRL+,) then open the Packages tab. Find script and open its Settings menu. The first setting is "Change Current Working Directory (CWD) Behavior." Change the value from "First project directory" to "Directory of script."
It could be that atom changes a file path.
Run a file or command to check
import os
print(os.getcwd())
This will tell you which dir you are working from.
Use this in your script to change dir
os.chdir(PATH_TO_DIR)
or write full file path
I created an application that is running at windows startup, but every time it give me an Error:
[Errno 2] No such file or directory: 'user'
that error happen only at startup, if I open it normally (with doubleclick) it works good.
Note: I created the .exe with Pyinstaller and the file called 'user' is in the same directory of .exe (Program Files/App1/main.exe)
Maybe autorun works like a temp folder that can't recognize the content of Program Files directory?
Your program should never count on the current working directory being the same as the directory it's run from. If the user runs your program from the command line, or you put it in a batch file, or you launch it from autorun, or another program tries to run it… in all those cases, the working directory will be somewhere else.
sys.argv[0] gives you the path to your program. So:
import sys
import os
scriptdir = os.path.dirname(os.path.abspath(sys.argv[0]))
userpath = os.path.join(scriptdir, 'user.exe')
I'm running OSX Mavericks but this problem has been going on since I had Snow Leopard.
When writing a script in any language, eg: Python. When I try to open a file the short
form doesn't work.
file = open('donkey.jpg')
And I get this error:
IOError: [Errno 2] No such file or directory: 'donkey.jpg'
Instead, I always have to specify the full path.
file = open('/Users/myName/Desktop/donkey.jpg')
Any ideas on why this could be happening and how to correct it?
If you specify donkey.png, it means donkey.jpg file in the current working directory. (relative path)
Make sure you're running the script in the same directory where donkey.jpg exists.
If you want specify the image file path relative to the script file instead of current working directory use following:
import os
filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'donkey.jpg')
NOTE You can use __file__ only in script file. (not in interactive mode)
Your open call does not have a mode parameter. In which case, it defaults to opening the file in read mode.
Unless the file you are opening (to read) resides in the current working directory, it is completely expected that the python script throws a IOError.