- How to Fix “bash: no such file or directory”
- How to Resolve the “no such file or directory”?
- Reason 1: Wrong File Name
- Solution: Check the File name and Path
- Reason 2: Wrong File Format
- Solution: Use the dos2unix Tool
- Conclusion
- «No such file or directory» but it’s there.
- 2 Answers 2
- Further Clarification as you asked in your comment
- ubuntu /usr/bin/env: python: No such file or directory
- 10 Answers 10
How to Fix “bash: no such file or directory”
Unlike other operating systems such as Windows, Linux is an OS in which the majority of its tasks are performed using the Terminal. One of the major tasks that the Linux terminal performs is the execution of programs using commands. While attempting to execute any program through this method, the user may come across this very common error statement which is the “no such file or directory” issue.
This article will elaborate on the reasons that prompt the error “no such file or directory” and also provide possible solutions to fix it
How to Resolve the “no such file or directory”?
Since this is a very general error, there are a few different reasons that can invoke this issue on the system. All these reasons are discussed below in great detail.
Reason 1: Wrong File Name
The first and the most commonly occurring reason is caused by using incorrect spellings of the file name. For example, the mistake can be the incorrect spelling of a file. Below is an example of such a mistake:
Solution: Check the File name and Path
In the example shown above, the bash file “sample.sh” is saved on the desktop. So, make sure that the error is not invoked by using the correct spellings and the correct path. Look at the following image where the name and path of the file are correct, and thus, the output is displayed:
Reason 2: Wrong File Format
The other most common cause behind this issue is that the file that is attempted to execute is in a different format than the operating system. Let’s take an example of this situation. The file that is executed using the command is a DOS file which is a script written for Windows. If this DOS file is executed in an Ubuntu system, the “no such file or directory” issue will be invoked.
Solution: Use the dos2unix Tool
There exists a very useful tool for exactly these types of scenarios. The dos2unix tool helps to convert a dos file to a script that can be read by the Ubuntu OS. The first step is to install the dos2unix tool using this command:
$ sudo apt install dos2unix
Once the tool is installed, convert the DOS file into an Ubuntu-compatible file using the following command:
The system should be able to run the script file without the error being prompted after the conversion is complete.
Conclusion
The “no such file or directory” issue occurs when the name or the path of the executable file is entered incorrectly into the terminal. Another reason is that Ubuntu is not able to read the DOS script and if it is executed on the Ubuntu terminal, then the error is prompted. To fix these issues it needs to be made sure that the file path and file name are entered correctly into the terminal. The other fix is to install the dos2unix tool and convert the dos files format to run on Ubuntu. This article has demonstrated the reasons and the solutions to fix the error “no such file or directory”.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY
«No such file or directory» but it’s there.
As you can see from the above I’m trying to go to the folder brian2 but Ubuntu tells me No such file or directory but the directory list command tells me it is there.
2 Answers 2
From home to enter brian2 from /home/ , type in terminal
When to say cd /brian2 , it tries to navigate the folder at / but there is no folder brian2
Further Clarification as you asked in your comment
Christian Mann aptly said it, tilde ~ refers the same thing as /home/brian2 in your case.
~ refers to home for any user. For example,
For brian ~ refers to /home/brian
For brian1 ~ refers to /home/brian1 so on.
If brian1 enters to brian’s home (have to have permission) he will see at prompt
In Linux always you can modify things. There is a special shell variable PS1 which can modify the shell prompt in different ways as you wish.
Just to clarify, the point is that / refers to the very top of the hierarchy of your system. home is a top-level directory under / so /home refers to the home directory at the top of the hierarchy and /home/brian2 refers to the brian2 directory inside the home directory, whereas /brian2 refers to the non-existent brian2 directory at the top of the hierarchy. cd can also check the current directory, so if you are in /home already, it will go to /home/brian2 if you type cd brian2 . cd /home/brian2 does the same thing.
I would have thought it would have brought me to . brian2@ubuntu:/home/brian2$ ?? Thanks for your patience! Brian
@brian If this answer has answered your question please accept it to help keep our site clean and orderly. Thanks!
ubuntu /usr/bin/env: python: No such file or directory
I update the kernel, after that the Ubuntu doesn’t work well, PS: I try to exec «meld» command, it will report that «/usr/bin/env: python: No such file or directory», then I exec «sudo apt-get install python» and get the result «python is already the newest version.», what should I do for it. I’m not good at linux, can you tell me how to revert my linux to the last right status, or reinstall the python normally.
Looks like you have the wrong PATH set in the environment at that point. Use ubuntu.stackexchange.com for ubuntu-specific questions!
10 Answers 10
Problem scenario:
/usr/bin/env: ‘python’: No such file or directory
Possible Solution #1
Possible Solution #2
- If Python 3 has been installed, run these commands: whereis python3
- Then we create a symlink to it: sudo ln -s /usr/bin/python3 /usr/bin/python
EDIT: hi everyone, I noticed that @mchid posted a better solution below my answer: sudo apt install python-is-python3 .
Worked for me as well with Ubuntu 20.04 except that I put the symbolic link into my /home/user/bin folder instead as I did not want to clutter up /usr/bin .
This obviously fixes this problem, but I’m a little shocked it’s the «correct» fix for this. Why isn’t the regular python3 on the system path being used? Is this the fault of the developer of the script/application? An old Python 2 standard that fell out of use? Is there some other reason this doesn’t «just work»?
@Manius, once I tried to remove Python2, I broke my distro so badly that even my Ethernet card wasn’t working. I had to manually port Python2 back to my distro with a USB sick and compile it from there. There are tons of legacy code that still need Python2 and believe me, we will not remove Python2 for a long time. For the same reason Windows still has to support all the old C++ libraries and version. It’s called Backward compatibility and that’s the price to pay. By default the distro needs Python2.
I have used the solution below, it feels more safe if it was shipped in an official apt repo sudo apt install python-is-python3 .
@FrancescoMantovani thanks, being new to Linux it took me a while to realize that it is just a symlink (a close relative of shortcut in Windows), which I can delete as and when I want. So, no it didn’t cause me any problem, but just wanted to undo.
On Ubuntu 20.04 and newer, there is a package to fix this problem. Run the following commands:
sudo apt update sudo apt install python-is-python3
Run apt-cache show python-is-python3 for more info.
I haven’t tested this yet, but assuming this works, it kinda seems like this is the «correct» or best answer here (SO vote count fails again) and that the problem is perhaps a result of a changing standard from python2 to 3. Is that accurate?
@Manius They answered in May and I didn’t answer until almost December. I mean, this pretty much does the same thing (creates a symlink) so «best» is kind of subjective. But yes, this seems to be a result of changing from python2 to python3 — there’s actually a package named python-is-python2 that creates a symlink to python2 for people who need to run old python software.
I get the timing difference yes. I thought subjectivity wasn’t allowed on SO? 😉 Just picking on SO’s arbitrary rule set. We could make an argument that manually creating a link is a distro-neutral solution, I suppose. Python has a way of agitating me to be extra critical for some reason. Python’s environment seems to be a mess whenever I need to deal with it.
Having been momentarily stumped by this error myself, I thought I’d post how I fixed my problem.
: No such file or directory
Which made little sense to me. My problem is that my editor had silently converted the script from Unix LF to Windows CR/LF line-termination. A rather unfortunate upshot of this is that «#!/usr/bin/env python» actually became «#!/usr/bin/env python\015» where \015 is the invisible CR character. /usr/bin/env was, then, unable to find a command «python\015» — hence the file-not-found error.
Converting the script to Unix line-ending convention solved my problem. but only after a few minutes’ head-scratching.
thank you very much. and as a side note you can convert win endings into unix endings by fromdos
You can use this in Vim editor to convert file format — :set ff=unix More details in this answer: stackoverflow.com/a/82743/9152071
@endolith it still isn’t (well I’m checking on Debian, but I think Ubuntu is the same, the shebang is parsed by Linux the kernel). But the error message is much better now: /usr/bin/env: ‘python3\r’: No such file or directory
May 2022: For anyone who just updated to Monterey 12.3 it appears the update replaces python with python3. Downloading python fixes the issues in Xcode and git command line. Be sure to read the two comments below.
For those that aren’t aware: Python 2 has been discontinued, it’s not even receiving security updates at this stage. It’s really quite important to upgrade to Python 3!
I’m using python via homebrew and got a similar error, so inspired by other answers, I ran sudo ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python and things magically worked again. Thanks
For people facing the same issue with MacOS and installed python3 with homebrew:
sudo ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python
@mchid’s answer is the one you should go for it.
it will say Command ‘python’ not found .
But if you do this: $ python3 , it should work.
So, just modify the shebang line
from !#/usr/bin/env python to !#/usr/bin/env python3 , you’re good to go.
(which is automatically done by doing sudo apt install python-is-python3 )
For those with macOS or M1 machines (tested on 12.5) symlinking /usr/bin/python3 will not work because it’s a reference to the xcode python3 installation. Instead do:
sudo ln -s /Library/Developer/CommandLineTools/usr/bin/python3 /usr/local/bin/python
This answer for android build system error For Python 3
If you get a «/usr/bin/env ‘python’ no such file or directory» error message, use one of the following solutions: If your Ubuntu 20.04.2 LTS is a newly installed (vs. upgraded) Linux version:
sudo ln -s /usr/bin/python3 /usr/bin/python
f using Git version 2.19 or greater, you can specify —partial-clone when performing repo init. This makes use of Git’s partial clone capability to only download Git objects when needed, instead of downloading everything. Because using partial clones means that many operations must communicate with the server, use the following if you’re a developer and you’re using a network with low latency:
repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M