I've installed Python 2.7.2 on my Windows XP computer.
I recently installed SQLAlchemy 0.7.1 using 'python setup.py install'. During the installation, I got the following error messages:
byte-compiling C:\Python27\Lib\site-packages\sqlalchemy\sql\visitors.py to visitors.pyc
SyntaxError: ('invalid syntax', ('C:\\Python27\\Lib\\site-packages\\sqlalchemy\\sql\\visitors.py', 66, 34, 'class Visitable(object, metaclass=VisitableType):\n'))
When I try to import sqlalchemy, I get the following stack trace:
>>> import sqlalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sqlalchemy\__init__.py", line 12, in <module>
from sqlalchemy.sql import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\__init__.py", line 7, in <module>
from sqlalchemy.sql.expression import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\expression.py", line 32, in <module>
from sqlalchemy import util, exc
File "C:\Python27\lib\site-packages\sqlalchemy\util\__init__.py", line 7, in <module>
from .compat import callable, cmp, reduce, defaultdict, py25_dict, \
File "C:\Python27\lib\site-packages\sqlalchemy\util\compat.py", line 93, in <module>
callable = __builtin__.callable
NameError: name '__builtin__' is not defined
Other scripts work fine and all the functions in __builtin__ seem to be available.
I can't find any examples of similar problems on Google or in the SQLAlchemy documentation.
What's wrong?
UPDATE:
Uncommenting import __builtin__ in compat.py removed the first problem. Now I seem to have problems with visitors.py:
>>> import sqlalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sqlalchemy\__init__.py", line 12, in <module>
from sqlalchemy.sql import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\__init__.py", line 7, in <module>
from sqlalchemy.sql.expression import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\expression.py", line 35, in <module>
from sqlalchemy.sql.visitors import Visitable, cloned_traverse
File "C:\Python27\lib\site-packages\sqlalchemy\sql\visitors.py", line 66
class Visitable(object, metaclass=VisitableType):
^
SyntaxError: invalid syntax
Problem partially solved: everything started working when I rolled back to SQLAlchemy 0.6.8. An issue with 0.7.1 + Windows/2.6?
Related
I'm having some issues running checkov, I'm not familiar with python libraries, anyone can give me some hints?
This is working fine in some machines but not in this one in particular...
Running in CentOS:
$ checkov --directory cdk.out
Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in <module>
from checkov.main import run
File "/usr/local/lib/python3.6/site-packages/checkov/main.py", line 22, in <module>
from checkov.terraform.plan_runner import Runner as tf_plan_runner
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/plan_runner.py", line 11, in <module>
from checkov.terraform.context_parsers.registry import parser_registry
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/__init__.py", line 1, in <module>
from checkov.terraform.context_parsers.parsers import *
File "/usr/local/lib/python3.6/site-packages/checkov/terraform/context_parsers/parsers/provider_context_parser.py", line 1, in <module>
import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/__init__.py", line 5, in <module>
from .api import load, loads
File "/usr/local/lib/python3.6/site-packages/hcl2/api.py", line 4, in <module>
from hcl2.parser import hcl2
File "/usr/local/lib/python3.6/site-packages/hcl2/parser.py", line 53, in <module>
hcl2 = Lark_StandAlone(transformer=DictTransformer())
File "/usr/local/lib/python3.6/site-packages/hcl2/lark_parser.py", line 8, in Lark_StandAlone
return Lark._load_from_dict(DATA, MEMO, **kwargs)
AttributeError: type object 'Lark' has no attribute '_load_from_dict'
After upgrading python from 3.6 to 3.8 and reinstalling checkov it worked just fine.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Anirudh\Documents\flask_app\connecting_to_database\application.py", line 2, in <module>
from flask_sqlalchemy import SQLAlchemy
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 18, in <module>
import sqlalchemy
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
from .sql import (
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
from .expression import (
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
from .visitors import Visitable
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
from .. import util
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
from .compat import callable, cmp, reduce, \
File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 234, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
I had this issue with SQLAlchemy 1.2.10. Upgrading to the current version (1.3.18 as of now) fixed the problem
pip install sqlalchemy --upgrade
The error occurs because in python 2, there is time.clock(), but in python 3, it has been replaced with time.perf_counter().
Just replace all the time.clock to time.perf_counter, and it should be fine. For more info: https://www.webucator.com/blog/2015/08/python-clocks-explained/
I found a solution that worked for me
I have a virtual environment carpet named env in which I installed sqlalchemy
So, env\Lib\site-packages\flask_sqlalchemy_init_.py
Inside that there is this code:
if sys.platform == 'win32':
_timer = time.clock
else:
_timer = time.time
And I changed clock to perf_counter()
_timer = time.perf_counter()
I have a script using openpyxl to add rows to an existing xlsx spreadsheet. It was running fine a couple of weeks ago: however, when I run it now, it starts to give me different syntax error in Python2 and Python3.
The problem I have is that the syntax error is pointing to the import packages rather than somewhere in code.
Any suggestion on how to fix these syntax issues?
Error with Python2
IDA-Data host$ python2 add_name_excel_dirs.py
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 400, in <module>
import UserDict
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 116, in <module>
import _abcoll
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_abcoll.py", line 662
def append(self, value: object) -> object:
^
SyntaxError: invalid syntax
Error with Python3 when running the same script:
IDA-Data host$ python3 add_name_excel_dirs.py
Traceback (most recent call last):
File "add_name_excel_dirs.py", line 5, in <module>
from openpyxl import load_workbook
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/openpyxl/__init__.py", line 26, in <module>
from openpyxl.compat.numbers import NUMPY, PANDAS
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/openpyxl/compat/__init__.py", line 5, in <module>
from .strings import (
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/openpyxl/compat/strings.py", line 9, in <module>
from .numbers import NUMERIC_TYPES
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/openpyxl/compat/numbers.py", line 28, in <module>
import pandas
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/__init__.py", line 58, in <module>
from pandas.io.api import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/api.py", line 10, in <module>
from pandas.io.pytables import HDFStore, get_store, read_hdf
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/pytables.py", line 918
def append(self, key: object, value: object, format: object = None, append: object = True, columns: object = None,
^
SyntaxError: non-default argument follows default argument
I'm new to Python and I'm trying to do a simple thread as follows.
import threading
def func(x):
print x
t1 = threading.Thread(target=func,args=("Hello",));
t1.start();
Then I got following error:
Traceback (most recent call last):
File "ex2.py", line 1, in <module>
import threading
File "/Users/treinetic-macbook/Desktop/threading.py", line 2, in <module>
File "/Library/Python/2.7/site-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/Library/Python/2.7/site-packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Python/2.7/site-packages/urllib3/connectionpool.py", line 3, in <module>
import logging
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 207, in <module>
_lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'
can someone help me to understand this error?
/Users/treinetic-macbook/Desktop/threading.py is being imported because it's on your path somewhere. This is most likely not correct, try renaming that file and removing any threading.pyc file in your local dir.
Traceback (most recent call last):
File "main.py", line 4, in <module>
from bot import bot
File "/root/musicbot/bot.py", line 7, in <module>
from database import db, text_search
File "/root/musicbot/database.py", line 2, in <module>
import pymongo
File "/usr/local/lib/python3.5/site-packages/pymongo/__init__.py", line 92, in <module>
from pymongo.connection import Connection
File "/usr/local/lib/python3.5/site-packages/pymongo/connection.py", line 39, in <module>
from pymongo.mongo_client import MongoClient
File "/usr/local/lib/python3.5/site-packages/pymongo/mongo_client.py", line 46, in <module>
from pymongo import (auth,
File "/usr/local/lib/python3.5/site-packages/pymongo/pool.py", line 22, in <module>
from pymongo import thread_util
File "/usr/local/lib/python3.5/site-packages/pymongo/thread_util.py", line 31, in <module>
from gevent.lock import BoundedSemaphore as GeventBoundedSemaphore
File "/usr/local/lib/python3.5/site-packages/gevent/__init__.py", line 36, in <module>
from gevent.hub import get_hub, iwait, wait
File "/usr/local/lib/python3.5/site-packages/gevent/hub.py", line 282
except Exception, ex:
^
SyntaxError: invalid syntax
You are using a Python package which is for Python 2.x and uses old Exception syntax (gevent.hub).
You need to upgrade the violating module to Python 3.x compatible version.
If this is not possible then you need to deploy your application on Python 2.x.