FileNotFoundError Python Script - python

I am trying to run a python script, .py in the windows command prompt.
I drag the script from my files into the command prompt window. I run it.
Then, the script presents a prompt for me to enter the file I would like to parse. I am supposed to enter a file like this: filename.txt
When I go to do this, I get the FileNotFoundError. They are both located in my downloads folder. Any ideas as to why? I've tried a couple of things but having no luck.
The script must be performed this way because this is a script many people will use and it is likely that they will receive it and download it and the file to parse to their computer so it'll be located in their downloads folder.
When I created the script I did it in Notepad++ and had a separate folder where I put the file and script and it worked fine this way. I am just ensuring it works from the perspective of someone who's downloading it off an email or website, etc.
Thanks !

Yeah that happened to me a lot.
To solve it just write the whole directory of the file.
If you are in windows
c:\user\username\Desktop\file.txt
If you are in linux or mac:
/home/username/Desktop/file.txt

Related

How to run Chariot using python script? "This app can't run on your PC"

Everyone. I met a issue says that "This app can't run on your PC" when I want to run the a .exe file using python script. The thing is I could run it in Command Prompt, it works well. but when I want to run it using python script in VS Code, it says
I tried many methods google from the Internet, it still doesn't work. Here is what I want to run in python
os.system(" cd C:\Program Files (x86)\Ixia\IxChariot ")
os.system(" runtst.exe -t20 C:\\Users\\Admin\\Documents\\IxChariot\\Tests\\mlo_delay.tst C:\\csv\\6G_d.tst ")
Does anyone have idea what is the issue and how to fix it? thx
First, please set permissions for your vscode. It seems that it runs files in the system disk. Then, you can use os.popen() to open files.
For example:
import os
google = "C:\Program Files\Google\Chrome\Application\chrome.exe"
os.popen(google)

Python Files running in the terminal however not running when i run the actual file after importing a library

my python files are running in the terminal, however when i actually run the .py file in file explorer they dont run, they only dont run after importing a non already installed python library, for example colorama.
Im really new to programming so any help appreciated.
My guess is that the python executable you associated with the .py filetype in your operating system is not executable you expect. This could happen, for instance, if you have both plain python and conda python on the same system.
The following is more of a suggestion than an answer, but it's too long to put in a comment:
First, try putting input('Press enter to continue...') at the end of your file, so the window won't close immediately on error.
Next, run the code import sys; print(sys.executable); print(sys.path); input('Press enter to continue...')
The output of the above code will tell you the exact location of your python executable as well as what folders your program draws your libraries from.
Please start VS Code in a project (workspace) folder.

How to get a file from the files on my computer to JupyterLab?

I am very new to this and struggling with the basics. I have a csv file /home/emily/Downloads/Roger-Federer.csv The textbook says that I need to "extract the file and download it to my current directory" on JupyterLab (I am using Python). What does this mean? How do I do this? Thank you
Every running program, including JupyterLab, has a "working directory" which is where it thinks it is on your computer's file system. What exactly this directory is usually depends on how you launched it (e.g., when you run a program from terminal, its working directory is initially the folder your terminal was in when you ran the command, but it's possible for a program to change its own working directory later).
Your file path indicates you're on Linux, so I'd suggest opening a terminal in your JupyterLab and running pwd to have it print out its current directory. (You can also run !pwd in any open notebook if that's easier.) You should then copy your CSV file to that directory.
If you do that, then from your Python code, you can just open the file locally, like open('Roger-Federer.csv') or pandas.read_csv('Roger-Federer.csv'). You don't have to move the file to open it from Python, though, you can just give it the entire file path, like open('/home/emily/Downloads/Roger-Federer.csv'), and that'll work just fine too.

Problems executing python script in notepad++

I have some images that load in my python script.
they reside in c:\Python27\subfolder\images\
in my .py file (which resides in c:\Python27\subfolder\ )
I load them with ./images/file.jpg
It works just fine in IDLE
However when I run the file through notepad++ I get the error:
Failed to load file ./images/file.jpg
How can I fix this with out having to change my actual python code? (It works if I load the images with the full path, but I dont want to do this).
Im using the run command C:\Python27\python.exe "$(FULL_CURRENT_PATH) in notepad++
thank you very much!!
Well to help you fix the problem, you should do this
import os
print os.getcwd() #gets the current working directory
Most likely your problem is that within the IDE, your CWD differs than when you're running it from the console.
If you want it to work like it does in the IDE, you should first get yourself (the console) within that directory, via navigation (os.chdir(...) command).
You could also make a batch/bash file that runs the python script from the directory you need, and call that file from wherever you want (it would still call the python script with the path you gave

How do I get a python program to run instead of opening in Notepad?

I am having some trouble with opening a .py file. I have a program that calls this .py file (i.e. pathname/example.py file.txt), but instead of running the python program, it opens it in Notepad. How to I get it to run?
The program itself takes in a file, and creates an output that is more readable.
Edit: The operating system is Windows 7. And the file that is calling the python is a .bat file.
Edit 2: It looks like I had to reinstall python for some reason... but it looks like it is finally working. Why reinstalling never comes to mind in the first place... And then I had to change how the file extention was opened. Thanks guys
This happened because most probably you have set notepad as the default program to open a .py file. Go to default programs app in windows. Select choose app by extension. Here search for .py files. Change the option from notepad to python. This should solve your problem.
okay.
1) i tried turning it off and on again.
2) i uninstalled and reinstalled python
still no joy. and then!
in windows explorer there's an open with option that sets the default program that windows is pointed toward if you click on the filename or enter it on the command line. change that from notepad or whatever it is if it's not python. change it to python. then presto. no problem-o.
You need to run it from the command line.
http://docs.python.org/2/faq/windows.html#how-do-i-run-a-python-program-under-windows
Are you trying to run the program like this?
/dirdir/MyPythonScript.py
try the following instead
python /dirdir/MyPythonScript.py

Categories