6

I have installed python and I have a file Wifite.py that exists in my current directory.

But whenever I try to run the Wifite2.py file I receive this error:

‘python’: No such file or directory

jarvus@jarvus:~/wifite2$ ls
bin          PMKID.md             setup.py   wordlist
Dockerfile   README.md            tests      wordlist-
EVILTWIN.md  reaver-wps-fork-t6x  TODO.md
LICENSE      runtests.sh          wifite
MANIFEST.in  setup.cfg            Wifite.py


jarvus@jarvus:~/wifite2$ ./Wifite.py
/usr/bin/env: ‘python’: No such file or directory

What changes should be made to get ./Wifite.py working?

The workaround I got is using:

python3 Wifite.py

But I'm looking for alternatives.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Prajwal Raju P
  • 180
  • 1
  • 3
  • 12

4 Answers4

6

This message:

/usr/bin/env: ‘python’: No such file or directory

suggests that the hashbang in your script looks like this:

#!/usr/bin/env python

Since running the script explicitly with python3 worked OK, it sounds like you're on a distro where by default you only have python3 and no python. As other answers suggest, you may install python-is-python3 (which basically creates a python symlink pointing to python3). If you don't wish to do that, then just adjust the script's hashbang so that /usr/bin/env looks for python3:

#!/usr/bin/env python3
Czaporka
  • 2,190
  • 3
  • 10
  • 23
  • Thanks, mate, what I ended up doing was changing the hashbang to "/usr/bin/env python" to "/usr/bin/env python3" in my python file and it solved the issue – Prajwal Raju P Jan 29 '21 at 10:44
  • https://stackoverflow.com/questions/71468590/env-python-no-such-file-or-directory-when-building-app-with-xcode Helpful answer. – 7bStan May 24 '22 at 06:58
  • 4
    `ln -s /usr/bin/python3 /usr/local/bin/python` Use this – 7bStan May 24 '22 at 06:59
2

Seems you don't have python2 installed but only python3 but it is not registered as plain python. Try

which python
which python2
which python3

If only the last command runs without error you can try to link python3 to python with

sudo apt-get install python-is-python3
fragmentedreality
  • 1,287
  • 9
  • 31
  • 2
    Don't. If it's `python3`, then use `python3` (in the shebang, when running scripts, ex). The OS may rely on `python` being an actual Python 2. – Gino Mempin Jan 28 '21 at 10:15
1

Use shebangs! In the first line of your script write the python interpretor path.

#! /usr/bin/python

Then chmod +x your file on shell. That will make it executable. And you can directly run it.

lllrnr101
  • 2,288
  • 2
  • 4
  • 15
0

Try running python3 Wifite2.py from the directory where the file exists.

Yuv_c
  • 88
  • 6
  • yes I got that working using this command but is there a way to get it working without passing the python command – Prajwal Raju P Jan 28 '21 at 09:57
  • No. Basically you are expecting your os to guess what to do with the file called "Wifite2.py". You could `python3 Wifite2.py`, you could `vim Wifite2.py` etc. If you want to run the script, you must specify it. – Yuv_c Jan 28 '21 at 10:03
  • 1
    @Yuv_c in Unix-like systems, [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) tells the OS exactly what program it should use to interpret the file. OP does have one in the script, as can be seen from the error message. Not having a shebang and still trying to execute the script like this is another story though - in that case the OS does indeed have to guess what to execute the script with, AFAIK its guess is usually `/bin/sh`. – Czaporka Jan 29 '21 at 04:51
  • I wasn't aware of that @Czaporka. Thanks for the explanation. – Yuv_c Jan 31 '21 at 08:23