I'm unable to import the timezonefinder Python library:
>>> import timezonefinder
Traceback (most recent call last):
File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/timezonefinder/__init__.py", line 2, in <module>
from .timezonefinder import TimezoneFinder File "/usr/local/lib/python2.7/dist-packages/timezonefinder/timezonefinder.py", line 300
def closest_timezone_at(self, *, lat, lng, delta_degree=1, exact_computation=False, return_distances=False,
^ SyntaxError: invalid syntax
Timezonefinder supports Python 3 only. You're using Python 2.
One immediate piece of evidence is that the syntax def f(a, *, b=xyz) is not valid in Python 2, as shown in your traceback.
You can always check a package's setup.py, which (should) hint at 'Programming Language :: Python :: 3 :: Only' for this limitation.
Related
I am trying to import the following library:
import json2xml
from json2xml.utils import readfromstring
However, when I execute the second line I get this error:
Traceback (most recent call last):
File "C:\Users\denis\Desktop\Pazaruvaj Upload\Pazaruvaj_Part1_Test.py", line 12, in <module>
from json2xml.utils import readfromurl, readfromstring, readfromjson
File "C:\Python27\lib\site-packages\json2xml\utils.py", line 19
def readfromjson(filename: str) -> dict:
^
SyntaxError: invalid syntax
Couldn't find anything online about this issue.
Note I don't write from json2xml import json2xml because it gives the same error
According to https://pypi.org/project/json2xml/, json2xml is not compatible with Python2.
Python2 is deprecated, please update to Python3. Then this library should work.
I am using the PyYAML-3.10 as part of a Python program on macOS 10, using Python version 2.7.10. I am not able to make sense of these compilation errors. Since PyYAML-3.10 is a stable version of PyYAML, it should give no compilation errors. The errors are listed below. Any suggestions would be appreciated.
File "pyR#TE.py", line 3, in <module>
import yaml
File "/Users/PyR#TE/pyrate-1.0.0/yaml/__init__.py", line 8, in <module>
from .loader import *
File "/Users/PyR#TE/pyrate-1.0.0/yaml/loader.py", line 4, in <module>
from .reader import *
File "/Users/PyR#TE/pyrate-1.0.0/yaml/reader.py", line 45, in <module>
class Reader(object):
File "/Users/PyR#TE/pyrate-1.0.0/yaml/reader.py", line 137, in Reader
NON_PRINTABLE = re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
raise error, v # invalid expression
sre_constants.error: bad character range
It seems that PyYAMP-3.10 is not compatible with Python 2. (Did you mean "PyYAML", by the way? I could not find a reference to a "PyYAMP" package anywhere.) The compilation error you are seeing is from re.compile - when Python is trying to compile a regular expression.
I tried using the line in your error message containing re.compile in Python 2 and Python 3.
Python 2:
>>> import re
>>> re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/re.py", line 194, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.7/re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: bad character range
>>>
Python 3:
>>> import re
>>> re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
re.compile('[^\t\n\r -~\x85\xa0-\ud7ff\ue000-�]')
>>>
So your options are either to find a package that supports Python 2, or to upgrade your code to Python 3. I recommend upgrading, as Python 2 is no longer supported.
[joepareti54#xxx build]$ ./manta ../scenes/_trainingData.py --dim 3 --addModelGeometry True --addSphereGeometry True
Version: mantaflow 64bit fp1 commit dd3bb0c0a65cc531d3c33487bde5edcb4aa6784f from Mar 14 2018, 14:53:44
Loading script '../scenes/_trainingData.py'
Traceback (most recent call last):
File "../scenes/_trainingData.py", line 12, in <module>
from Emitter import *
File "/home/joepareti54/FluidNet/manta/scenes/Emitter.py", line 15, in <module>
import matlabnoise
File "/home/joepareti54/FluidNet/manta/build/../../../matlabnoise/matlabnoise.py", line 81
def Perlin2D(*args) -> "double" :
^
SyntaxError: invalid syntax
I believe the invalid syntax occurs in:
def Perlin2D(*args) -> "double" :`enter code here`
return _matlabnoise.Perlin2D(*args)
Perlin2D = _matlabnoise.Perlin2D
Your problem is that mantaflow is running an embedded Python, so the version used is the one that was available when mantaflow was compiled and it appears that version does not support the type annotations introduced in Python 3.5
When you run which python that shows you the version of Python installed on your system, not the version compiled into the other program.
Solutions include recompiling mantaflow with a more recent Python, or stop using type annotations.
I'm having a problem with Travis on every commit. My tests work on local but on Travis I get this error:
Traceback (most recent call last):
File "/opt/python/3.2.5/lib/python3.2/unittest/case.py", line 370, in _executeTestPart
function()
File "/opt/python/3.2.5/lib/python3.2/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: test.test_parser
Traceback (most recent call last):
File "/opt/python/3.2.5/lib/python3.2/unittest/loader.py", line 261, in _find_tests
module = self._get_module_from_name(name)
File "/opt/python/3.2.5/lib/python3.2/unittest/loader.py", line 239, in _get_module_from_name
__import__(name)
File "/home/travis/build/davidmogar/genderator/test/test_parser.py", line 5, in <module>
import genderator
File "/home/travis/build/davidmogar/genderator/genderator/__init__.py", line 3, in <module>
from genderator.parser import Parser
File "/home/travis/build/davidmogar/genderator/genderator/parser.py", line 5, in <module>
from .utils import Normalizer
File "/home/travis/build/davidmogar/genderator/genderator/utils.py", line 63
u'\N{COMBINING TILDE}'
^
SyntaxError: invalid syntax
Here is the code where that line is:
def remove_accent_marks(text):
good_accents = {
u'\N{COMBINING TILDE}',
u'\N{COMBINING CEDILLA}'
}
return ''.join(c for c in unicodedata.normalize('NFKD', text)
if unicodedata.category(c) != 'Mn' or c in good_accents)
I have no idea about what is the problem because as I've said, all test are working in local. Here is my .travis.yml file:
language: python
python:
- "3.2"
- "3.3"
- "3.4"
script: python -m unittest discover
Any idea?
The u'...' syntax in Python 3 is only supported in Python 3.3 and up.
The u prefix is only there to support polyglot Python code (supporting both 2 and 3), and can be safely removed if you don't need to support Python 2.
If you need to support both Python 2 and 3.2, you'll have to use a different approach. You could use a from __future__ import to make all string literals in Python 2 produce unicode string objects; this applies per module:
from __future__ import unicode_literals
def remove_accent_marks(text):
good_accents = {
'\N{COMBINING TILDE}',
'\N{COMBINING CEDILLA}'
}
The strings will be treated as Unicode in both Python 2 and 3.
Or you could create your own polyglot function:
import sys
if sys.version_info[0] < 3:
u = lambda s: unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
else:
u = lambda s: s
and use that on all your Unicode strings:
def remove_accent_marks(text):
good_accents = {
u('\N{COMBINING TILDE}'),
u('\N{COMBINING CEDILLA}')
}
or you can use the six library to produce that bridge for you:
import six
def remove_accent_marks(text):
good_accents = {
six.u('\N{COMBINING TILDE}'),
six.u('\N{COMBINING CEDILLA}')
}
You may want to read the Python Porting HOWTO.
I'm using Pyshark and Python 2.6 on OS X 10.10. I simply try to import pyshark in my code, and this error is thrown. Any idea of what could be going wrong?
/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 "/Users/spencergardner/Google Drive/development/python-sockets/sniff.py"
Traceback (most recent call last):
File "/Users/spencergardner/Google Drive/development/python-sockets/sniff.py", line 1, in <module>
import pyshark
File "/Library/Python/2.6/site-packages/pyshark/__init__.py", line 1, in <module>
from pyshark.capture.live_capture import LiveCapture
File "/Library/Python/2.6/site-packages/pyshark/capture/live_capture.py", line 1, in <module>
from pyshark.capture.capture import Capture
File "/Library/Python/2.6/site-packages/pyshark/capture/capture.py", line 12, in <module>
from pyshark.tshark.tshark_xml import packet_from_xml_packet, psml_structure_from_xml
File "/Library/Python/2.6/site-packages/pyshark/tshark/tshark_xml.py", line 5, in <module>
from pyshark.packet.layer import Layer
File "/Library/Python/2.6/site-packages/pyshark/packet/layer.py", line 57
return {slot: getattr(self, slot) for slot in self.__slots__}
^
SyntaxError: invalid syntax
The error is due to using a dictionary comprehension, a language feature that was introduced to Python 2 in 2.7, not the 2.6 you're trying to use. Apple ships OS X 10.10 with both 2.7 and 2.6. Is there a reason you can't use 2.7 instead?