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
Related
When i try to import pandas in a python code it gives me the error:
File "Traceback (most recent call last):
File "c:\Users\Adrian\Desktop\alkemy\src\py_functions\transform_univ_jfk.py", line 4, in <module>
import pandas as pd
File "C:\Users\Adrian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\__init__.py", line 141, in <module>
from pandas.io.api import (
File "C:\Users\Adrian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\api.py", line 6, in <module>
from pandas.io.excel import (
File "C:\Users\Adrian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\excel\__init__.py", line 1, in <module>
from pandas.io.excel._base import (
File "C:\Users\Adrian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\excel\_base.py", line 75, in <module>
from pandas.io.parsers import TextParser
File "C:\Users\Adrian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\io\parsers\__init__.py", line 1, in <module>
from pandas.io.parsers.readers import (
ValueError: source code string cannot contain null bytes
I was using python until about a month ago without errors, my cousin used my computer for a few days and I don't know what she did, I reinstalled python and it still gives me errors
I have a portable python version to use within C:\temp
I wanted to test what version of pandas is included by writing a "scrip"t that import pandas as pd and pritns the pandas version.
I usually start python via the command line which now returned an "Syntax" error in a file that I have never touched.
c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App>python.exe packagesTest.py
Traceback (most recent call last):
File "packagesTest.py", line 1, in <module>
import pandas as pd
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\__init__.py", line 27, in <module>
from pandas.core.api import *
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\api.py", line 14, in <module>
from pandas.core.frame import DataFrame
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\frame.py", line 33, in <module>
from pandas.core.internals import (BlockManager,
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\internals\__init__.py", line 1, in <module>
from pandas.core.internals.blocks import ( # io.pytables, io.packers
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\internals\blocks.py", line 97
values: Union[np.ndarray, ExtensionArray]
^
SyntaxError: invalid syntax
I am completly new when it comes to these kind of "Error messages". maybe someone can help with what is wrong here.
Pandas Core Internal block
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
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.
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.