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

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

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

zeppelin_ipyspark.py at apache zeppelin get SyntaxError: invalid syntax

when i running code with pyspark in apache zeppelin 0.8.1 , i get error like
java.lang.NullPointerException
at org.apache.thrift.transport.TSocket.open(TSocket.java:170)
at org.apache.zeppelin.interpreter.remote.ClientFactory.create(ClientFactory.java:51)
...
so i open all file in my folder zeppelin
and i try to running file zeppelin_ipyspark.py at D:\zeppelin-0.8.1-bin-all\interpreter\spark\python with cmd
and i get error
D:\zeppelin-0.8.1-bin-all\interpreter\spark\python>zeppelin_ipyspark.py
File "D:\zeppelin-0.8.1-bin-all\interpreter\spark\python\zeppelin_ipyspark.py", line 29
port=${JVM_GATEWAY_PORT}, auth_token=gateway_secret, auto_convert=True))
^
SyntaxError: invalid syntax
so can you help me?
#LSS zeppelin_ipyspark.py is not a standalone script.
It is invoked internally from Zeppelin's java code as part of Ipython interpreter, where the python script is processed to replace these strings(like JVM_GATEWAY_PORT etc) with actual values.
You can check the code references: 1, 2

Linux: all commands return Fatal Python error: Py_Initialize: Unable to get the locale encoding

I was messing around with my Path variables and after putting the following 3 commands, every shell command I execute would return a Fatal Python error:
export PYTHONPATH=$PYTHONPATH:z3/bin
export PATH=$PATH:z3/bin
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7
Error message:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
File "/usr/lib/python2.7/encodings/init.py", line 123
raise CodecRegistryError,\
^ SyntaxError: invalid syntax Aborted
Does anyone how can I fix this? I am running Ubuntu 14.04.

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

A error about pyuic4

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

Categories

Resources