Spyder: Interaction with pint pkg. SyntaxError raised

Created on 24 Oct 2017  路  7Comments  路  Source: spyder-ide/spyder

Description of your problem

When working with the pint package, Spyder raises an error when trying to understand the input.

What steps will reproduce the problem?

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg(

As soon as the open parenthesis is entered, the following error is given in a window (shown below). Copying and pasting the infringing line into the command window works and the code can execute, so something is going wrong with the command line inspection. This worked fine in Spyder version 3.2.3.

What is the expected output?

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg('1m')
>>> 1 meter

What do you see instead?

  File "C:\Anaconda3\lib\site-packages\qtconsole\base_frontend_mixin.py", line 163, in _dispatch
    handler(msg)
  File "C:\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\namespacebrowser.py", line 220, in _handle_execute_reply
    self.handle_exec_method(msg)
  File "C:\Anaconda3\lib\site-packages\spyder\widgets\ipythonconsole\shell.py", line 392, in handle_exec_method
    self._kernel_reply = ast.literal_eval(data['text/plain'])
  File "C:\Anaconda3\lib\ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Anaconda3\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 3
    'name': <bound method BaseRegistry.__name__ of <pint.registry.UnitRegistry object at 0x000001AFE39B4F60>>,
            ^
SyntaxError: invalid syntax

Versions and main components

PS C:\Anaconda3\Scripts> .\conda.exe list | Select-String -Pattern ("^#|^python\s+|^spyder\s+|^pyqt\s+|^qt\s+")

# packages in environment at C:\Anaconda3:
#
pyqt                      5.6.0            py36hb5ed885_5
python                    3.6.3                h9e2ca53_1
qt                        5.6.2           vc14h6f8c307_12  [vc14]
spyder                    3.2.4            py36h8845eaa_0
  • Operating system: Windows 10 x64 1703 (OS Build 15063.674)

Dependencies

IPython >=4.0 : 6.1.0 (OK)
cython >=0.21 : 0.26.1 (OK)
jedi >=0.9.0 : 0.10.2 (OK)
nbconvert >=4.0 : 5.3.1 (OK)
numpy >=1.7 : 1.13.3 (OK)
pandas >=0.13.1 : 0.20.3 (OK)
pycodestyle >=2.3: 2.3.1 (OK)
pyflakes >=0.6.0 : 1.6.0 (OK)
pygments >=2.0 : 2.2.0 (OK)
pylint >=0.25 : 1.7.4 (OK)
qtconsole >=4.2.0: 4.3.1 (OK)
rope >=0.9.4 : 0.10.5 (OK)
sphinx >=0.6.6 : 1.6.3 (OK)
sympy >=0.7.3 : 1.1.1 (OK)

IPython Console Bug

All 7 comments

Thanks for reporting.

@dalthviz, please take a look at this one.

@ccordoba12 @JesterEE I tested this but it works for me. Something to notice is that I tested with Windows 8.1. Also, something that I'm not sure if its ok, is the result I receive: <Quantity(1, 'meter')>:

pint

Edit:

Packages in environment

alabaster                 0.7.10           py36hcd07829_0
asn1crypto                0.22.0           py36h8e79faa_1
astroid                   1.5.3            py36h9d85297_0
babel                     2.5.0            py36h35444c1_0
bleach                    2.0.0            py36h0a7e3d6_0
ca-certificates           2017.08.26           h94faf87_0
cachecontrol              0.12.3           py36hfe50d7b_0
certifi                   2017.7.27.1      py36h043bc9e_0
cffi                      1.10.0           py36hae3d1b5_1
chardet                   3.0.4            py36h420ce6e_1
colorama                  0.3.9            py36h029ae33_0
cryptography              2.0.3            py36h123decb_1
cython                    0.26.1           py36h18049ac_0
decorator                 4.1.2            py36he63a57b_0
distlib                   0.2.5            py36h51371be_0
docutils                  0.14             py36h6012d8f_0
entrypoints               0.2.3            py36hfd66bb0_2
fastcache                 1.0.2            py36hffdae1b_0
html5lib                  0.999999999      py36ha09b1f3_0
icu                       58.2             vc14hc45fdbb_0  [vc14]
idna                      2.6              py36h148d497_1
imagesize                 0.7.1            py36he29f638_0
ipykernel                 4.6.1            py36hbb77b34_0
ipython                   6.1.0            py36h236ecc8_1
ipython_genutils          0.2.0            py36h3c5d0ee_0
isort                     4.2.15           py36h6198cc5_0
jedi                      0.10.2           py36hed927a0_0
jinja2                    2.9.6            py36h10aa3a0_1
jpeg                      9b               vc14h4d7706e_1  [vc14]
jsonschema                2.6.0            py36h7636477_0
jupyter_client            5.1.0            py36h9902a9a_0
jupyter_core              4.3.0            py36h511e818_0
lazy-object-proxy         1.3.1            py36hd1c21d2_0
libpng                    1.6.32           vc14h5163883_3  [vc14]
lockfile                  0.12.2           py36h0468280_0
markupsafe                1.0              py36h0e26971_1
mccabe                    0.6.1            py36hb41005a_1
mistune                   0.7.4            py36h4874169_0
mpmath                    0.19             py36he326802_2
msgpack-python            0.4.8            py36h58b1e9d_0
nbconvert                 5.3.1            py36h8dc0fde_0
nbformat                  4.4.0            py36h3a5bc1b_0
numpydoc                  0.7.0            py36ha25429e_0
openssl                   1.0.2l           vc14hcac20b0_2  [vc14]
packaging                 16.8             py36ha0986f6_1
pandoc                    1.19.2.1             hb2460c7_1
pandocfilters             1.4.2            py36h3ef6317_1
pickleshare               0.7.4            py36h9de030f_0
pint                      0.8.1                    py36_0    conda-forge
pip                       9.0.1            py36hadba87b_3
progress                  1.3              py36hbeca8d3_0
prompt_toolkit            1.0.15           py36h60b8f86_0
psutil                    5.4.0            py36h4e662fb_0
pycodestyle               2.3.1            py36h7cc55cd_0
pycparser                 2.18             py36hd053e01_1
pyflakes                  1.6.0            py36h0b975d6_0
pygments                  2.2.0            py36hb010967_0
pylint                    1.7.4            py36ha4e6ded_0
pyopenssl                 17.2.0           py36h15ca2fc_0
pyparsing                 2.2.0            py36h785a196_1
pyqt                      5.6.0            py36hb5ed885_5
pysocks                   1.6.7            py36h698d350_1
python                    3.6.3                h9e2ca53_1
python-dateutil           2.6.1            py36h509ddcb_1
pytz                      2017.2           py36h05d413f_1
pyzmq                     16.0.2           py36h38c27d9_2
qt                        5.6.2           vc14h6f8c307_12  [vc14]
qtawesome                 0.4.4            py36h5aa48f6_0
qtconsole                 4.3.1            py36h99a29a9_0
qtpy                      1.3.1            py36hb8717c5_0
requests                  2.18.4           py36h4371aae_1
rope                      0.10.5           py36hcaf5641_0
setuptools                36.5.0           py36h65f9e6e_0
simplegeneric             0.8.1            py36heab741f_0
sip                       4.18.1           py36h9c25514_2
six                       1.11.0           py36h4db2310_1
snowballstemmer           1.2.1            py36h763602f_0
sphinx                    1.6.3            py36h9bb690b_0
sphinxcontrib             1.0              py36hbbac3d2_1
sphinxcontrib-websupport  1.0.1            py36hb5e5916_1
spyder                    3.2.4            py36h8845eaa_0
sqlite                    3.20.1           vc14h7ce8c62_1  [vc14]
sympy                     1.1.1            py36h96708e0_0
testpath                  0.3.1            py36h2698cfe_0
tornado                   4.5.2            py36h57f6048_0
traitlets                 4.3.2            py36h096827d_0
typing                    3.6.2            py36hb035bda_0
urllib3                   1.22             py36h276f60a_0
vc                        14                   h2379b0c_2
vs2015_runtime            14.0.25123           hd4c4e62_2
wcwidth                   0.1.7            py36h3d5aa90_0
webencodings              0.5.1            py36h67c50ae_1
wheel                     0.29.0           py36h6ce6cde_1
win_inet_pton             1.0.1            py36he67d7fd_1
wincertstore              0.2              py36h7fe50ca_0
wrapt                     1.10.11          py36he5f5981_0
zlib                      1.2.11           vc14h1cdd9ab_1  [vc14]

@dalthviz

Thanks for checking in on this. The output you are receiving is correct. pint is a units package and it returns numeric quantities with an associated unit so you can work with scaling and converting easily. If you have the need for such things, it's great and I recommend it! Odd that its working for you! I downgraded to spyder 3.2.3 in the interim to get some other work done ... let me try this again over the weekend. I'll try a force install from conda and see if I still get an issue. Please leave this open for a few days.

So some weird stuff happened, but I don't think it will be too helpful here.

I rebooted Windows 10 while still having Spyder 3.2.3 installed and upon start-up, Spyder wouldn't open even though it did before the reboot. I figured a file must have been corrupted so I force installed 3.2.4 from conda and I still couldn't start Spyder. While updating, I saw that a spyder-script.py was installed and after looking into it I decided to run it with the --reset argument. I ran that (which deleted all my settings, history, lock files, etc.), and Spyder started without issue, and the bug I originally reported was no longer present.

So, either I needed the fresh install due to corruption, or there was some settings issue causing a conflict. Either way, it is now resolved. I will close this issue.

Thanks for the feedback @JesterEE :+1:

I found the issue that is causing this error (and it still exists).

After clearing my settings from older Spyder installations, I started re-implementing my preferences and the issue came back. I cleared it again and started activating them one by one till the test case above gave the error and I found it!

The issue I was seeing is due to setting Preferences -> Help -> Automatic Connections -> IPython Console

There seems to be an issue interfacing with this object from my IPython console and the help screen tab. Note, that this will not cause an issue from the Editor. This setting does not even need to be activated to see this error. The user can also either Cntr+I ureg( in the console or type ureg into the Help -> Object search with Source = Console to get the same error.

I am reopening this issue.

This is present on Mac OS as well and in Spyder 4.0.0.b2. This does not manifest in QtConsole run from the command line. I confirm the exact behavior just described by @JesterEE.

Was this page helpful?
0 / 5 - 0 ratings