A error about pyuic4 - python

I'm trying to transform my ui file to .py file, but when I run pyuic4 in the shell, I get an error:
# pyuic4 main.ui > main_ui.py
File "/usr/lib/python2.7/site-packages/PyQt4/uic/pyuic.py", line 2
exec /usr/bin/python /usr/lib/python2.7/site-packages/PyQt4/uic/pyuic.py ${1+"$#"}
^
SyntaxError: invalid syntax
my os is fedora16

On Linux, pyuic4 should be a bash script that would usually be installed as /usr/bin/pyuic4.
The error
exec /usr/bin/python /usr/lib/python2.7/site-packages/PyQt4/uic/pyuic.py ${1+"$#"}
^
SyntaxError: invalid syntax
would be produced if you attempted to run that bash script with python.
However, the error message also gives the source file location as
File "/usr/lib/python2.7/site-packages/PyQt4/uic/pyuic.py", line 2
which doesn't make much sense, because that should be a python script.
Has /usr/lib/python2.7/site-packages/PyQt4/uic/pyuic.py somehow been over-written with the bash script?
Try opening that file, and also /usr/bin/pyuic4, in an editor to see what they contain.

If you want use python2, just type
python2-pyuic4 main.ui > main_ui.py

Related

Pyinstaller - invalid syntax

I am trying to use pyinstaller to package my script into an exe.
All sources indicate that the correct syntax is: pyinstaller FullClientCreator.py
When I issue this command, I get a syntax error:
pyinstaller FullClientCreator.py
File "C:\Users\DAVIDM~1\AppData\Local\Temp/ipykernel_7368/3509825318.py", line 1
pyinstaller FullClientCreator.py
^
SyntaxError: invalid syntax
I also tried it with the full path for the file, and I still get the same error:
pyinstaller "D:\Projects\ZZNew Client CreatorZZ\FullClientCreator.py"
File "C:\Users\DAVIDM~1\AppData\Local\Temp/ipykernel_7368/546891165.py", line 1
pyinstaller "D:\Projects\ZZNew Client CreatorZZ\FullClientCreator.py"
^
SyntaxError: invalid syntax
I am at a complete loss as to why this could be, so if anyone has any suggestions, I would greatly appreciate them.
Try another shell
I dont know which shell are you using but if you're using python shell sometimes its not working for python shell so try it on your cmd
pyinstaller --onefile file.py

Syntax error: invalid syntax. File "<stdin">, line 1

I have just started python and stuck in this error. While typing python helloworld.py this error is occurring My helloworld.py file is openning in windows cmd but it's not opening in python.exe

install error or error running python file

I am running a basic Python file on Windows XP from IDLE.
The file name is assignment1.py.
The file content is:
import sys
var = 5
but when I run it, it gives the error:
Command: python assignment1.py
SyntaxError: invalid syntax
Then I tried another thing which also gave an error:
Command: which python
SyntaxError: invalid syntax
Not sure if the installation is wrong or something.
I am able to run the print command successfully:
>>> print "I am working fine"
I am working fine
Not sure of the issue. Request help.
It looks like what you are entering as the "command" is being interpreted as Python code. I mean, python assignment1.py is interpreted as Python code. The result is as expected:
$ python -c 'python assignment1.py'
File "<string>", line 1
python assignment1.py
^
SyntaxError: invalid syntax
You need to run the file in the correct way, probably via the IDLE menu or by pressing F5. You can check these questions for details:
How do I run a Python program?
Running Python script from IDLE on Windows 7 64 bit

Relative Python Path to Script

Python project looks like this:
setup.py
README
Application
scripts
hello.py
shell_scripts
date.sh
From hello.py I'm executing the command subprocess.call(['../shell_scripts/date.sh']) and receiving the error OSError: [Errno 8] Exec format error.
Note: date.sh is a perfectly valid shell script and is executable. I've also tried os.path.realpath to no avail.
I assume this is due to an invalid path?
Exec format error will come when the shell isn't set at the script. try adding #!/bin/sh at the beginning of the script and execute the python script.

Python+ubuntu error

Am trying to run the following python program
import re
regex=re.compile("http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]")
f=open('out.txt')
for a in f:
print regex.findall(a)
print '\n'
when I type the code into the interpreter manually, it works as expected
but when i save it as a file and try to run it , it gives errors.
The command i used to run it is
chmod +x
sudo ./pymod.py
ERROR:
./pymod.py: 2: Syntax error: "(" unexpected
if i dont use sudo, the error i get is
./pymod.py: line 2: syntax error near unexpected token `('
./pymod.py: line 2: `regex=re.compile("http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]")'
am using ubuntu 10.04 with everything on default
it takes about 10-15 seconds for the error to appear
Your file should start with shebang. You should include the path to the python interpreter
#!/usr/bin/env python
import re
regex=re.compile("http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]")
Check out : http://en.wikipedia.org/wiki/Shebang_(Unix)
This is probably executing as a bash script instead of in Python. Put
#!/usr/bin/env python
at the beginning of your script.
When you set something as executable, you have to specify what you want it to run it with, or Linux will consider it to be a bash script.
Add this as the first line of the file:
#!/usr/bin/python
Or run it like:
python pymod.py
Cheers!
Either use the "shebang". I.e. put
#! /usr/bin/python
as the first line of your script.
Or teach your ubuntu how to treat python scripts without it
as described here: http://www.daniweb.com/code/snippet241988.html

Categories

Resources