I'm new to python and I am trying to transfer data in a PostgreSQL database with the postgis extension. My code is written in Python 2.7 and I am using the PyCharm IDE.
When I am trying to import the postgis module:
import postgis
I get an 'invalid syntax' error:
Traceback (most recent call last):
File "/home/.../PycharmProjects/HDFtoPostgres/SendToPSQL.py", line 1, in <module>
import postgis
File "/home/.../PycharmProjects/HDFtoPostgres/venv2.7/lib/python2.7/site-packages/postgis/__init__.py", line 2, in <module>
from .geometry import Geometry
File "/home/.../PycharmProjects/HDFtoPostgres/venv2.7/lib/python2.7/site-packages/postgis/geometry.py", line 14
class Geometry(object, metaclass=Typed):
^
SyntaxError: invalid syntax
To me it looks like the geometry.py is written in Python 3.x but is interpreted as Python 2.7 and thus crashes at this point. Any ideas on how to solve this?
It would appear that the postgis
package shouldn't really install in Python 2 environments, since its page on PyPI suggests it's only approved for Python 3.5 and 3.6.
There isn't really an easy way around this other than to migrate your code to Python 3 if postgis
is an essential component. Alternatively you might try backporting postgis
to Python 2.7, but that's an exercise of unknown complexity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.