在 Python 2.7 中导入 postgis 时如何修复无效语法错误?
How do I fix invalid syntax error when importing postgis in Python 2.7?
我是 python 的新手,我正在尝试使用 postgis 扩展在 PostgreSQL 数据库中传输数据。我的代码是用 Python 2.7 编写的,我使用的是 PyCharm IDE。
当我尝试导入 postgis 模块时:
import postgis
我收到 'invalid syntax' 错误:
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
对我来说,geometry.py 似乎是用 Python 3.x 编写的,但被解释为 Python 2.7,因此此时崩溃。关于如何解决这个问题的任何想法?
看来 postgis
软件包不应该真正安装在 Python 2 环境中,因为 its page on PyPI 表明它只被批准用于 Python 3.5 和 3.6。
如果 postgis
是必不可少的组件,除了将您的代码迁移到 Python 3 之外,没有真正简单的解决方法。或者,您可以尝试将 postgis
反向移植到 Python 2.7,但这是一个未知复杂性的练习。
我是 python 的新手,我正在尝试使用 postgis 扩展在 PostgreSQL 数据库中传输数据。我的代码是用 Python 2.7 编写的,我使用的是 PyCharm IDE。
当我尝试导入 postgis 模块时:
import postgis
我收到 'invalid syntax' 错误:
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
对我来说,geometry.py 似乎是用 Python 3.x 编写的,但被解释为 Python 2.7,因此此时崩溃。关于如何解决这个问题的任何想法?
看来 postgis
软件包不应该真正安装在 Python 2 环境中,因为 its page on PyPI 表明它只被批准用于 Python 3.5 和 3.6。
如果 postgis
是必不可少的组件,除了将您的代码迁移到 Python 3 之外,没有真正简单的解决方法。或者,您可以尝试将 postgis
反向移植到 Python 2.7,但这是一个未知复杂性的练习。