question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

itk, swig, and Spyder don't play nice?

See original GitHub issue

Problem Description

Importing ITK package works properly in Terminal but not Spyder. Specifically:

import itk
itk.Image[itk.UC, 2]

Throws this error in Spyder: TypeError: coercing to Unicode: need string or buffer, list found (Spyder 2.7 in Anaconda 2.7 root environment)

Works properly in Terminal.

What steps will reproduce the problem?

  1. Install itk either from source or via Anaconda (on my machine error persists regardless of how itk is installed).
  2. enter commands above
  3. ensure $ echo $PYTHONPATH gives same python path in os.environ in Spyder

What is the expected output? What do you see instead?

Expectation (from terminal)

import itk
itk.Image[itk.UC, 2]
# <class 'itkImagePython.itkImageUC2'>

Instead in Spyder: TypeError

Paste Traceback/Error Below (if applicable)

import itk

itk.Image[itk.UC, 2]

Traceback (most recent call last):

  File "<ipython-input-2-5f5da1089460>", line 1, in <module>
    itk.Image[itk.UC, 2]

  File "/home/sumathipalaya/ITK4.11_WithPythonShared/lib/python2.7/dist-packages/itkLazy.py", line 44, in __getattribute__
    itkBase.LoadModule(module, namespace)

  File "/home/sumathipalaya/ITK4.11_WithPythonShared/lib/python2.7/dist-packages/itkBase.py", line 118, in LoadModule
    LoadModule(dep, namespace)

  File "/home/sumathipalaya/ITK4.11_WithPythonShared/lib/python2.7/dist-packages/itkBase.py", line 128, in LoadModule
    module = loader.load(swigModuleName)

  File "/home/sumathipalaya/ITK4.11_WithPythonShared/lib/python2.7/dist-packages/itkBase.py", line 250, in load
    return imp.load_module(name, fp, pathname, description)

  File "/home/sumathipalaya/ITK4.11_WithPythonShared/lib/python2.7/dist-packages/itk/Configuration/../ITKPyBasePython.py", line 21, in <module>
    _ITKPyBasePython = swig_import_helper()

  File "/home/sumathipalaya/ITK4.11_WithPythonShared/lib/python2.7/dist-packages/itk/Configuration/../ITKPyBasePython.py", line 18, in swig_import_helper
    return importlib.import_module(mname)

  File "/home/sumathipalaya/anaconda2/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

  File "/home/sumathipalaya/anaconda2/lib/python2.7/site-packages/pyximport/pyximport.py", line 302, in find_module
    elif os.path.isfile(path):

  File "/home/sumathipalaya/anaconda2/lib/python2.7/genericpath.py", line 37, in isfile
    st = os.stat(path)

TypeError: coercing to Unicode: need string or buffer, list found

N.B. This link seems to have some helpful information, but I don’t understand how to interpret it. Any help or guidance would be appreciated.

Package Versions

  • Spyder: 3.2.7
  • Python: 2.7
  • Qt: 5.6.2
  • PyQt: 5.6.0
  • Operating System: Ubuntu 14.04

Dependencies

IPython >=4.0;<6.0:  5.4.1 (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)
psutil >=0.3      :  5.4.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pyflakes >=0.5.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)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ysumath1commented, Mar 14, 2018

You know, I think I misread when it was closed; I mistakenly took the date Carlos added the tags as the date this was closed. Thanks so much for clarifying. I’m always impressed by how responsive your team is to improving this IDE!

1reaction
ysumath1commented, Mar 14, 2018

Thanks. Looked like the issue was closed in Sept. 2017; as there’s been a couple of releases of Spyder since then; I had presumed the issue was fixed and thus wanted to report what I thought was a bug. Glad to see a proper solution is coming out in the newest release. I will wait for it and update accordingly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verbalicious - Don't Play Nice - YouTube
http://bit.ly/verbaliciousOne from the archives, for some reason this has never been put on the channel before. Brilliant record all the way ...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
{10,12}: sysprof-modules crashes system when playing music" status:RESOLVED ... Bug:290280 - "Would be nice to have a @python-update set for portage" ...
Read more >
[Example code]-building extension for Python 3 with Swig and distutils
I've built an application ("Checkyrs") in C++, and now am doing something external which will use large parts of Checkyrs but is built...
Read more >
conda-forge - :: Anaconda.org
astmonkey, 0.3.6, Apache-2.0, X, astmonkey is a set of tools to play with Python AST. ... astpretty, 2.1.0, MIT, X, Pretty print the...
Read more >
Python Scientific lecture notes
Under Python(x,y), you can use Spyder. Under Ubuntu, if you don't already have your favorite editor, we would advise installing Stani's Python editor....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found