How to run pyautogui on mac? - python

I simply tried to run a code by importing pyautogui module, using the position function.
However, every time, I got the following error:
Traceback (most recent call last):
File "/Users/rahulbansal/Desktop/gfg/try.py", line 1, in <module>
import pyautogui
File "/Library/Python/2.7/site-packages/pyautogui/__init__.py", line 241, in <module>
import mouseinfo
File "/Users/rahulbansal/Library/Python/2.7/lib/python/site-packages/mouseinfo/__init__.py", line 100, in <module>
from rubicon.objc import ObjCClass, CGPoint
File "/Users/rahulbansal/Library/Python/2.7/lib/python/site-packages/rubicon/objc/__init__.py", line 3, in <module>
from .runtime import ( # noqa: F401
File "/Users/rahulbansal/Library/Python/2.7/lib/python/site-packages/rubicon/objc/runtime.py", line 785
self.restype, *self.argtypes = ctypes_for_method_encoding(self.encoding)
^
SyntaxError: invalid syntax

Related

Checkov error: AttributeError: type object 'Lark' has no attribute '_load_from_dict

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.

Recent syntax error using Python2 vs. Python3

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

Test framework quits unexpectedly - IntelliJ python plugin

I'm having a big problem with the testing framework in IntelliJ using with the python plugin.
When I launch my tests, written using unittest, the tests fail with an import error in the _jb_test_runner file.
I surfed the net for a while, but didn't get a useful solution. See the stacktrace below:
/usr/bin/python3.5 /home/davide/.IntelliJIdea2017.1/config/plugins/python/helpers/pycharm/_jb_unittest_runner.py --path /home/davide/Scrivania/musical-store/test/types/test_person.py
Testing started at 12.35 ...
Traceback (most recent call last):
File "/home/davide/.IntelliJIdea2017.1/config/plugins/python/helpers/pycharm/_jb_unittest_runner.py", line 4, in <module>
from unittest import main
File "/usr/lib/python3.5/unittest/__init__.py", line 58, in <module>
from .result import TestResult
File "/usr/lib/python3.5/unittest/result.py", line 5, in <module>
import traceback
File "/usr/lib/python3.5/traceback.py", line 5, in <module>
import linecache
File "/usr/lib/python3.5/linecache.py", line 8, in <module>
import functools
File "/usr/lib/python3.5/functools.py", line 22, in <module>
from types import MappingProxyType
ImportError: cannot import name 'MappingProxyType'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 62, in apport_excepthook
import re, traceback
File "/usr/lib/python3.5/traceback.py", line 5, in <module>
import linecache
File "/usr/lib/python3.5/linecache.py", line 8, in <module>
import functools
File "/usr/lib/python3.5/functools.py", line 22, in <module>
from types import MappingProxyType
ImportError: cannot import name 'MappingProxyType'
Original exception was:
Traceback (most recent call last):
File "/home/davide/.IntelliJIdea2017.1/config/plugins/python/helpers/pycharm/_jb_unittest_runner.py", line 4, in <module>
from unittest import main
File "/usr/lib/python3.5/unittest/__init__.py", line 58, in <module>
from .result import TestResult
File "/usr/lib/python3.5/unittest/result.py", line 5, in <module>
import traceback
File "/usr/lib/python3.5/traceback.py", line 5, in <module>
import linecache
File "/usr/lib/python3.5/linecache.py", line 8, in <module>
import functools
File "/usr/lib/python3.5/functools.py", line 22, in <module>
from types import MappingProxyType
ImportError: cannot import name 'MappingProxyType'
Process finished with exit code 1
The code does not present any syntax error, but the problem started after a refactoring of the whole project I'm working on.
Thanks in advance.

Error after "from new import instancemethod" when importing scipy.stats

I am getting an exception from scipy whenever I try to import the nltk package. The command and the error looks like this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 176, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 43, in <module>
from new import instancemethod
File "new.py", line 107
return copy.deepcopy(self)
^
IndentationError: expected an indented block
I executed this command in a terminal (ubuntu 16.04 LTS system). I did not find anything about this error and the indentation doesn't look wrong.
The SyntaxError is in your file new.py (I guess it's in your current working directory). Try to switch to a directory where no new.py file is present (or move the new.py file in another directory), then the internal scipy import should work without problems.
On the other hand you can just upgrade to scipy 0.19.x. They removed the import there and it should work without problems.
Note that it's always a bad idea to name python files like builtin-modules! That's a common source for exceptions or unexpected behaviour.

/gevent/hub.py: except Exception, ex: SyntaxError

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.

Categories