1

I'm starting to work with python and running into an issue where scripts will execute fine in terminal when called with python, py, or python3* but when trying to execute directly through the web or via cron with full paths, it constantly produces an error saying;

/usr/local/bin/python3.8: No such file or directory
/usr/bin/python3: No such file or directory
/usr/bin/python: No such file or directory

Below are the results when running various commands

which python
/usr/bin/python

which python2
/usr/bin/python2

which python3
/usr/bin/python3

which python3.8
/usr/local/bin/python3.8



# ls /bin/ | grep python
abrt-action-analyze-python
python
python2
python2.7
python2.7-config
python2-config
python3
python3.6
python3.6m
python-config


# echo "$PATH" | tr ':' '\n'
/root/.yarn/bin
/root/.config/yarn/global/node_modules/.bin
/usr/local/cpanel/3rdparty/lib/path-bin
/usr/local/cpanel/3rdparty/lib/path-bin
/usr/lib64/qt-3.3/bin
/usr/local/cpanel/3rdparty/lib/path-bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/opt/cpanel/composer/bin
/root/bin
/usr/local/bin


#whereis python
python:
/usr/bin/python3.6
/usr/bin/python2.7
/usr/bin/python3.6m
/usr/bin/python2.7-config
/usr/bin/python
/usr/lib/python3.6
/usr/lib/python2.7
/usr/lib64/python3.6
/usr/lib64/python2.7
/etc/python /usr/local/bin/python3.8
/usr/local/bin/python3.8-config
/usr/local/lib/python3.6
/usr/local/lib/python3.8
/usr/include/python2.7
/usr/include/python3.6m
/usr/share/man/man1/python.1.gz

whereis python3
python3:
/usr/bin/python3.6 
/usr/bin/python3.6m 
/usr/bin/python3 
/usr/lib/python3.6 
/usr/lib64/python3.6 
/usr/local/bin/python3.8 
/usr/local/bin/python3 
/usr/local/bin/python3.8-config 
/usr/local/lib/python3.6 
/usr/local/lib/python3.8 
/usr/include/python3.6m 
/usr/share/man/man1/python3.1.gz

Any advice on what to check on?

  • Use `type`, not `which`. – Barmar Dec 14 '21 at 01:06
  • What, exactly, do you mean by "trying to execute directly through the web"? – Tim Roberts Dec 14 '21 at 01:21
  • @Barmar # type python python is /usr/bin/python # type python3 python3 is /usr/bin/python3 # type python3.8 python3.8 is /usr/local/bin/python3.8 – VeryEarlyRandD Dec 14 '21 at 01:23
  • @TimRoberts site.url/file.py (when using the python path at the top of the file) which generates Internal Server errors and the 'not found' errors in the apache error log. – VeryEarlyRandD Dec 14 '21 at 01:25
  • 1
    Are you talking about a `#!/usr/bin/python` line at the beginning of the script? – Barmar Dec 14 '21 at 01:26
  • I don't see how `which python` can print `/usr/bin/python` if that path does not exist. – John Gordon Dec 14 '21 at 01:26
  • 2
    I suspect there's a CRLF line ending there. – Barmar Dec 14 '21 at 01:27
  • Yes. If you copied this file from a Windows system, then it has CR/LF line endings. The shebang `#!` lines at the beginning of the file are actually interpreted by the Linux kernel, which only understands LF endings. Your file name would be "/usr/bin/python". – Tim Roberts Dec 14 '21 at 01:30
  • Quick question: If you follow this article. Does it still fail? https://gavinwiener.medium.com/how-to-schedule-a-python-script-cron-job-dea6cbf69f4e – Muniko Dec 14 '21 at 01:30
  • @JohnGordon If `/usr/bin/python` is a symbolic link to a file that does not exist, that's exactly what you'd see. `which` would work, but executing would get a "file not found". – Tim Roberts Dec 14 '21 at 01:31
  • @Barmar Yes, I am using a windows system to develop and upload the files but linux to run. – VeryEarlyRandD Dec 14 '21 at 01:41
  • Tell your editor to use Unix line endings, or use `dos2unix` when you upload the files to Linux. – Barmar Dec 14 '21 at 01:42
  • @Barmar Still happens after running dos2unix on a hello world script. !#/usr/bin/env python import cgitb cgitb.enable() print("Content-Type:text/html;charset=utf-8") print() print("Hello world") – VeryEarlyRandD Dec 14 '21 at 01:57
  • I thought you were using the absolute path, not `/usr/bin/env` – Barmar Dec 14 '21 at 01:58
  • @Barmar Sorry, that was the latest attempt. Attempts with !#/usr/bin/python !#/usr/bin/python2 !#/usr/bin/python3 !#/usr/local/bin/python3.8 all produced the same thing – VeryEarlyRandD Dec 14 '21 at 02:08
  • If this only happens in the webserver, maybe it's running in a chroot jail that doesn't have python in it? – Barmar Dec 14 '21 at 02:10
  • @Barmar Does that happen by default or special user process? This is a dedicated system and the first time to trying to run anything python beyond command line python / python3 executions. – VeryEarlyRandD Dec 14 '21 at 02:35
  • I don't think it's the standard way webservers are configured, it's an added security. – Barmar Dec 14 '21 at 03:34

0 Answers0