How to fix cannot open file Test.py: [Errno2] No such file or directory?

2024/10/6 1:53:48

I tried to run a python script which does not exist in current folder, for example

C:\>python Test.py

python:can't open file 'Test.py':[Errno2] No such file or directory

I have to specify the absolute path c:\testdir\test.py to make the command workable.

c:\python c:\testdir\Test.py

I tried to append "c:\testdir" into Env argument 'PATH', but it still doesn't work.

i want to use the filename rather than the entire path, c:\python Test.py can i make it happen?

Answer

That means you're not currently in C:/testdir (you're in C:). Enter cd C:\testdir in your terminal to move to that directory (cd = change directory).

The reason you have to specify the entire path while out of the folder is because even if you're not in the folder that you're trying to reference, you can still use its path to reference it.

https://en.xdnf.cn/q/120189.html

Related Q&A

Highlight cells in a column in google spreadsheet when the value above a threshold with python

Here is a simplified example of my codes and the screenshot of the results I want to get in google spreadsheet. I hope to either save the dataframe style to google spreadsheet as applying table style t…

cannot concatenate str and file objects : Python error

I have Following piece of code: for src_filename, src_code in src_dict.iteritems(): try: set.dependencies = subprocess.check_output(unifdef -s /home/c/maindir/folder/ +src_filename, shell=True) except…

Run python script from html button submit

i have a code input data to txt file :<form action="proses.php" method="post">Nomor Polisi : <br><input type="text" name="nopol"><br><…

Reading log files in python

I have a log file (it is named data.log) containing data that I would like to read and manipulate. The file is structured as follows:#Comment line 1 #Comment line 2 1.00000000,3.02502604,343260.6865…

Return more than one value in python function [duplicate]

This question already has answers here:How can I use `return` to get back multiple values from a loop? Can I put them in a list?(2 answers)Closed 1 year ago.I was trying to use *args with a for loop …

Python: Making a class to use complex numbers

I am currently trying to write a program that deals with complex numbers. I have to use classes and methods. I am trying to be able to add, subtract, multiply etc., complex numbers, as well as compare …

Return does not return anything in Spyder. It works fine with other IDE

I just moved to spyder for Python and the return function doesnt seem to work: def test():return 2 test()The IPython console is empty. If I use print instead of return it works fine. Any idea? I use p…

Error in goto module [Python]

Ok, let me start by saying I know that it is bad that I am using the goto module and I shouldnt be and blah blah blah. However, for this specific purpose I need it. Let me also say that I am new to Pyt…

How to scrape all product review from lazada in python

i currently working on web scraping of data from the lazada site using selenium in python: https://www.lazada.sg/products/loreal-paris-uv-perfect-even-complexion-sunscreen-spf50pa-30ml-i214861100-s325…

How to compare 2 successive row values in a resultset object using python

I have a table issue_logs:id | issue_id | from_status | to_status | up_date | remarks ----+----------+-------------+-----------+----------------------------------+----------…