After hours of unsuccessfully trying to use objectpath in a Python3-script, I made the following simple experiment:
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
Expected output: 1
Success with python (2)
~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
1
>>>
Error with python3:
Is there something wrong with my installation of Python3 ?
objectpath in P3 neither works in scripts nor on console
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
Traceback (most recent call last):
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 398, in tokenize_python
yield type_map[t[0]], t[1]
KeyError: 4
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/interpreter.py", line 605, in execute
tree=self.compile(expr)
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/interpreter.py", line 38, in compile
ret=EXPR_CACHE[expr]=parse(expr,self.D)
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 464, in parse
r=expression().getTree()
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 449, in expression
left=t.led(left)
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 264, in led
advance()
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 161, in advance
token=nextToken()
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 413, in tokenize
for ID, value in source:
File "/home/lisa/.local/lib/python3.6/site-
packages/objectpath/core/parser.py", line 405, in tokenize_python
raise SyntaxError("Syntax error")
To run this in Python 3.x you should pip3 install objectpath otherwise it won't work.
See below how I ran your code:
dell#dell-XPS-15-9572:~/Desktop$ pip3 install objectpath
Collecting objectpath
Downloading https://files.pythonhosted.org/packages/21/6a/ed435be72edd1d60b7363cbb38c34aff3004fee02d1c7f9f01435c318cdb/objectpath-0.5-py2.py3-none-any.whl
Installing collected packages: objectpath
Successfully installed objectpath-0.5
dell#dell-XPS-15-9572:~/Desktop$ python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
1
>>>
Related
The problem occurred: ImportError: libhdf5.so.101: cannot open shared object file: No such file or directory,when I install pygrib on linux(centOS6) by Anaconda
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygrib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libhdf5.so.101: cannot open shared object file: No such file or directory
>>> exit()
================================================================
[root#localhost ll]# locate libhdf5.so.101
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
Please help me,thank you!
To overcome the limitations of pickle, I switched to multiprocessing_on_dill.
This started to generate an error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 107, in spawn_main
exitcode = _main(fd)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 117, in _main
self = reduction.pickle.load(from_parent)
ModuleNotFoundError: No module named '__builtin__'
Is there a way to overcome it?
Surprisingly, it still references C:\ProgramData\Anaconda3\lib\multiprocessing\.
While multiprocessing_on_dill has its own folder C:\ProgramData\Anaconda3\Lib\site-packages\multiprocessing_on_dill with the same set of files.
I'd suggest you use multiprocess instead of multiprocessing_on_dill... the former is better supported, and maintained by the dill author (me). It looks like multiprocess_on_dill is looking for __builtin__, which is where the builtin functions lived in python 2... in python 3, they are in builtins
>$ python
Python 2.7.16 (default, Apr 1 2019, 14:50:56)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import __builtin__
>>>
>$ python
Python 3.6.8 (default, Dec 30 2018, 13:04:41)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import __builtin__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '__builtin__'
>>> import builtins
>>>
So, I think it's either you are running python 3, and using the python 2 version of the code -- or the module doesn't fully support python 3.
Why python can't get evironment variable after export?
How to fix this?
λ: export AUTOTEST=/home/anton/eltx/scripts/gitlab/
~
λ: python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['AUTOTEST']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
raise KeyError(key)
KeyError: 'AUTOTEST'
>>>
>>> os.environ.get('AUTOTEST', 'none_value')
'none_value'
>>>
I found the mistake. There was an alias for running python
I have installed TensorFlow and wanted to check the installation. Here is the interaction with the python console.
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 106, in <module>
from tensorflow.python.platform import test
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/platform/test.py", line 81, in <module>
import mock # pylint: disable=g-import-not-at-top,unused-import
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/mock.py", line 81, in <module>
inspectsignature = funcsigs.signature
AttributeError: 'module' object has no attribute 'signature'
>>>
Could anyone please tell what I am doing wrong? Thanks.
As Yaroslav noted, this is most likely from running too old a version of Python, or you don't have the funcsigs package installed. For the latter, try pip install funcsigs
I am trying to work on manipulating excel sheets in python with openpyxl module
I am trying to load excel work book in my local system
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openpyxl
>>>
>>> wb = openpyxl.load_workbook('GCD_FINAL_OUTPUT.xlsx')
>>>
>>>
Which is working fine
But i tried the same in amazon aws(cloud instance) machine
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openpyxl
>>> wb = openpyxl.load_workbook('GCD_FINAL_OUTPUT.xlsx')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 201, in load_workbook
apply_stylesheet(archive, wb) # bind styles to workbook
File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 164, in apply_stylesheet
stylesheet = Stylesheet.from_tree(node)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 99, in from_tree
return super(Stylesheet, cls).from_tree(node)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/descriptors/serialisable.py", line 89, in from_tree
return cls(**attrib)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 90, in __init__
self.named_styles = self._merge_named_styles()
File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/stylesheet.py", line 110, in _merge_named_styles
xf = self.cellStyleXfs[style.xfId]
File "/usr/local/lib/python2.7/dist-packages/openpyxl/styles/cell_style.py", line 182, in __getitem__
return self.xf[idx]
IndexError: list index out of range
>>>
Which is throwing some random error
how could i fix and make it working??
The module versions from my local and cloud differs.
By install correct module it works fine