I'm running a script and I get a comma error:
dbconfigure -a abc -d ...
Traceback (most recent call last):
File "/usr/local/bin/dbconf", line 6, in <module>
from dbconf import main
File "/usr/local/lib/python3.7/site-packages/dbconf/__init__.py", line 308
except SDBResponseError, exc:
^
SyntaxError: invalid syntax
So I think the script uses a python command but the python command on my computer points to a python3 version. How do I fix this?
You can put the shebang header on Unix (including mac os). First line of your script should be #! /usr/bin/env python2
Related
I am running the following print statement in a file test.py within the Eclipse PyDev environment which gives the required output:
print(f"Epoch {j}: {self.evaluate(test_data)} / {n_test}")
However, when I attempt to run the same code from the file at the command prompt (OSX Terminal), I get the following
% python test.py
Traceback (most recent call last):
File "test.py", line 7, in <module>
import simple_nn
File "/Users/davidklemitz/eclipse-workspace/_neural/simple_nn.py", line 47
print(f"Epoch {j}: {self.evaluate(test_data)} / {n_test}")
^
SyntaxError: invalid syntax
Anybody have some clues to resolve the issue, thanks ?
Looks like you use two different python versions in Eclipse and your terminal. Try
python3 test.py
in your terminal
I installed pyAudioAnalysis on python2.7 using pycharm (linux). Trying to run audioBasicIO.py gives the following error. I have installed eyeD3 but it does not work.
/usr/bin/python2.7 /usr/local/lib/python2.7/dist-packages/pyAudioAnalysis/audioBasicIO.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pyAudioAnalysis/audioBasicIO.py", line 6, in <module>
import eyed3
File "/home/.local/lib/python2.7/site-packages/eyed3/__init__.py", line 31, in <module>
from .utils.log import log # noqa: E402
File "/home/.local/lib/python2.7/site-packages/eyed3/utils/__init__.py", line 361
msg = f"invalid level choice: {level} (choose from {parser.log_levels})"
^
SyntaxError: invalid syntax
Is my installation incorrect? This is the first time I use this library, does anyone have any suggestions.
f-strings aren't supported for python 2.7. You need python 3.6 or above to use them. Here is a good workaround, in which you can use f-strings in below python 3.6.
I'm using PYTHONWARNINGS="error::Warning" to raise exceptions on warnings, but I want to ignore certain such exceptions, which is normally fine. When the exception that results is SyntaxError, I would sometimes like to ignore that but don't know how.
Detailed example:
# has_deprecated_syntax.py
"""this becomes invalid: \* """
Then:
`$PYTHONWARNINGS="error::Warning" python3.6 -c "import has_deprecated_syntax"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/davidchudzicki/temp/so/has_deprecated_syntax.py", line 1
"""this becomes invalid: \* """
^
SyntaxError: invalid escape sequence \*
These attempts to ignore it both got me the same failure:
PYTHONWARNINGS="error::Warning,default::Warning:has_deprecated_syntax" python3.6 -c "import has_deprecated_syntax"
and
PYTHONWARNINGS="error::Warning,default::SyntaxError" python3.6 -c "import has_deprecated_syntax"
For reference, here's what makes me think this is the correct environment setting in general for ignoring warnings from particular modules:
With:
# has_warning.py
import warnings
warnings.warn("hi")
... I get:
$PYTHONWARNINGS="error::Warning" python -c "import has_warning"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "has_warning.py", line 3, in <module>
warnings.warn("hi")
UserWarning: hi
...which I can ignore with:
$PYTHONWARNINGS="error::Warning,default::Warning:has_warning" python -c
"import has_warning"
has_warning.py:3: UserWarning: hi
warnings.warn("hi")
But it doesn't work for SyntaxError. Is there any way to ignore those from particular modules?
(Note: I've constructed a small example for this question, but the real reason I care is that I want to fail on warnings in continuous integration for package I help with, but I get the SyntaxError from one of our dependencies when I do this.)
You can't ignore SyntaxError. It's not a warning, it's an error.
while running npm install (e.g. https://github.com/donpark/html2jade), I run into this error:
/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py:852: Warning: 'as' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp", line 15, in <module>
import gyp
File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 8, in <module>
import gyp.input
File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 852
except ImportError as e:
^
SyntaxError: invalid syntax
python --version generates 'Python 2.7.1'
This would not be a syntax error in Python 2.7.1. A quick workaround would be to run this programme as python /full/path/to/scriptname.py, which will actually use Python 2.7.1.
Getting this error when running pip install -U selenium. Mid way through the script, it gets the following SyntaxError:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Python32\Scripts\build\rdflib\setup.py", line 6, in <module>
from rdflib import __version__
File "rdflib\__init__.py", line 64, in <module>
from rdflib.term import URIRef, BNode, Literal, Variable
File "rdflib\term.py", line 367
except TypeError, te:
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Python32\Scripts\build\rdflib\setup.py", line 6, in <module>
from rdflib import __version__
File "rdflib\__init__.py", line 64, in <module>
from rdflib.term import URIRef, BNode, Literal, Variable
File "rdflib\term.py", line 367
except TypeError, te:
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Since it is a Syntax Error, I assume it is a python version problem, I'm running 3.2.2.
Pip did come with a pip-3.2.exe file, which I tried to run. But I got the same error. I'm pretty new to Python so it might be something simple.
And how can it be a syntaxError? pip is an already made program.
Running Win7, Python 3.2.2
Selenium does not support Python 3. Use Python 2.7 instead.
Sadly, almost all Python software requires Python 2.x.
[Update]
Selenium supports Python 3.x now.