I am working on a simple webapp from Head First Python. I am using ubuntu 14.04. But it is the error:
Traceback (most recent call last):
File "/usr/lib/python3.4/http/server.py", line 1143, in run_cgi
os.execve(scriptfile, args, env)
FileNotFoundError: [Errno 2] No such file or directory:
'/home/sarthak/Desktop/Learn/HeadFirstPython/chapter7/webapp/cgi-bin/generate_list.py'
127.0.0.1 - - [12/Jun/2015 07:08:25] CGI script exit status 0x7f00
The file surely exists on the system and it is made executable.
How to fix the problem?
The Problem lies in the 'wrong' path of the shebang line (the first line which says #!/usr/local/bin/python3) of the generate_list.py file.
If you are using ubuntu the location of python3 is probably /usr/bin/python3 (You can find out your python3 location by typing which python3 into the shell/terminal). So you have to adjust the first line to the actual address of python3 in order to make your script work.
Related
I'm running on Linux Debian 9 and PyCharmwith web scraping purposes; I'm currently using Python 3.5 as interpreter.
The script is the following:
from selenium import webdriver
import time
import datetime
from selenium.webdriver.common.keys import Keys
Till here, the script works fine, by importing the packages properly; when I try to set the driver by running the following line:
driver = webdriver.Firefox(executable_path='/home/quant/Desktop/DataDownload/venv/bin/geckodriver')
I get the following error message, relative to a format problem:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/quant/Desktop/DataDownload/venv/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 157, in __init__
self.service.start()
File "/home/quant/Desktop/DataDownload/venv/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
Browsing on the web, I found that probably this problem comes out when the executable program has not been unzipped and made executable correctly; to do that, I followed the steps below, by running them on the terminal:
(1).zip file download from the official repository in the github website:
wget [here][1]
(2) unzipped the file:
cd /home/quant/Downloads
tar -xvzf geckodriver-v0.21.0-arm7hf.tar.gz
(3) made the file executable:
chmod +x geckodriver
(4) moved the file on the following path:
mv geckodriver /home/quant/PycharmProject/DataDownloads/venv/bin/
Could someone help me to understand what's wrong, please?
Thanks in advance all!!
[Errno 8] Exec format error
This means you are trying to run a version of geckodriver that is compiled for a different architecture... you downloaded the ARM version (geckodriver-v0.21.0-arm7hf.tar.gz) and are most likely running on a x86/amd64 machine.
Solution:
go back to the geckodriver releases page and download the correct version for your system: https://github.com/mozilla/geckodriver/releases.
For example, if you are running 64 bit Linux, you want to download: geckodriver-v0.21.0-linux64.tar.gz
Installed Jython from the installer.
Set the Path as follows /Users/user/jython2.7.0/bin.
When tried to run Jython, received the following error.
MacBook-Pro:~ user$ jython
Traceback (most recent call last):
File "/Users/user/jython2.7.0/bin/jython", line 444, in <module>
main(sys.argv)
File "/Users/user/jython2.7.0/bin/jython", line 431, in main
os.execvp(command[0], command[1:])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 346, in execvp
_execvpe(file, args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 370, in _execvpe
func(file, *argrest)
OSError: [Errno 2] No such file or directory
Tried uninstalling other packages installed through Homebrew. But nothing positive.
Jython runs with the command java -jar jython.jar from the installation directory.
Tried running on a clean Macbook, everything runs fine.
Resolved the problem by pointing JAVA_HOME to jdk1.8.0_131 rather than jdk9.0.4. Not sure why this solution works.
python 2.7. Notepad++. Windows 10
I'm trying to open file like this:
sourcefile=raw_input('name of the file: ')
fhand=open(sourcefile,'r')
And it gives me this error:
Traceback (most recent call last):
File "C:\Users\Denis\Desktop\prog\python\es.py", line 135, in <module>
fhand=open(sourcefile)
IOError: [Errno 2] No such file or directory: '20.04.2016.csv'
In notepad++ i run this: C:\Python27\python.exe -i "$(FULL_CURRENT_PATH)"
Kinda new to programming but i'm guesing that I have to specify somehow path to the place where my es.py and my file is. I thought $(FULL_CURRENT_PATH) does it.
If i run my code with python or idle it works fine.
I've tried to run this program in Atom, gives same mistake. No mistakes so long as I don't work with files.
I have a bash script which helps establish a local SimpleHTTPServer.
python -m SimpleHTTPServer 8080
I have put this inside my project folder. While I am running the program by using:
subprocess.call('./setup.sh')
an error message comes out:
Traceback (most recent call last):
File "test.py", line 2, in <module>
subprocess.call('./setup.sh')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__
errread, errwrite)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1326, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
I retried this in terminal
localhost:Desktop XXXX$ sh setup.sh
Serving HTTP on 0.0.0.0 port 8080 ...
It is working fine.
I remember there are a few times where the terminal has popped up a window ask me about the permission for python about something related to firewall and I allowed it. Can you help me?
Run it exactly as you would on the shell, i.e., as sh ./setup.sh:
subprocess.call('sh ./setup.sh', shell=True)
That should do the trick. Most likely, your setup.sh is not set to executable or is missing the first #! line that marks its interpreter.
EDIT:
Make sure to set shell=True to execute it via the shell, if you pass it as a single string, or separate the parameters into a list, as you might with execve:
subprocess.call(['sh', './setup.sh'])
Give subprocess.Popen() a try, with cwd param:
subprocess.Popen(['sh', './setup.sh'], cwd='/dir/contains/setup.sh/')
I'm trying to setup elaphe on Mac. When I try generate some barcode using the terminal, with command python + /.../file.py elaphe works OK and generates the barcode correctly. But when I try to execute through web (php) I get the following error in the Apache's error logs:
Traceback (most recent call last):
File "lib/barcode_generator/generator.py", line 19, in <module>
code_39_image.save(str(random)+'.tif')
File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/Image.py", line 1406, in save
self.load()
File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
**File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)**
If I were in Windows I would say it is a problem with the path and the program can't find the "gs.write" but in Mac I'm a rookie, I don't know if it's the same, nevertheless I've already include this 2 path:
export PATH=/Users/x/Library/Python/2.7/bin:$PATH
export PATH=/usr/local/bin:$PATH
I would appreciate can give some ideas regarding this error.
Thanks in advance.
Fixed via a symbolic link. Clearly was a PATH issue or hardcoded reference to the gs binary.
sudo ln -s /usr/local/bin/gs /usr/bin/gs