spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.1k stars 1.57k forks source link

Frozen importlib._bootstrap on second import #9254

Closed jennirinker closed 5 years ago

jennirinker commented 5 years ago

Issue Report Checklist

Problem Description

On a second import, my script is giving a KeyError from importlib._bootstrap instead of properly reloading a submodule. If I manually enter the single line in the script in the ipython prompt, it works without issue.

What steps reproduce the problem?

  1. Install PyConTurb using the instructions here. (Sorry, I couldn't reproduce it with another package.)
  2. Create a module error.py with a single line: from pyconturb.io.hawc2 import dat_to_df. 2a. If you can't recreate this error, I'm running spyder from a different environment than my pyconturb environment and you might need to recreate my environment setup. I can provide details on this if needed.
  3. Run script once. It should work. Run it again, you get the error reprinted below.

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

I expect a one-line module to be able to run more than once, but instead I get the traceback printed in the next section.

Paste Traceback/Error Below (if applicable)


Traceback (most recent call last):

  File "<ipython-input-10-2437b3b92216>", line 1, in <module>
    runfile('C:/Users/rink/git/master-esperanza/rink_code/test_hawc2_turb.py', wdir='C:/Users/rink/git/master-esperanza/rink_code')

  File "C:\Users\rink\AppData\Local\Continuum\miniconda3\envs\espe\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\rink\AppData\Local\Continuum\miniconda3\envs\espe\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/rink/git/master-esperanza/rink_code/test_hawc2_turb.py", line 10, in <module>
    from pyconturb.io.hawc2 import dat_to_df

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 890, in _find_spec

  File "<frozen importlib._bootstrap>", line 864, in _find_spec_legacy

  File "C:\Users\rink\AppData\Local\Continuum\miniconda3\envs\espe\lib\site-packages\IPython\external\qt_loaders.py", line 48, in find_module
    if path:

  File "<frozen importlib._bootstrap_external>", line 1000, in __len__

  File "<frozen importlib._bootstrap_external>", line 982, in _recalculate

  File "<frozen importlib._bootstrap_external>", line 978, in _get_parent_path

KeyError: 'pyconturb'

Versions

Spyder environment:

PyConTurb environment (also Python 3.6):

Other info:

Dependencies

IPython >=4.0     :  7.2.0 (OK)
cython >=0.21     :  None (NOK)
jedi >=0.9.0      :  0.13.2 (OK)
matplotlib >=2.0.0:  3.0.2 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
numpy >=1.7       :  1.15.4 (OK)
pandas >=0.13.1   :  0.24.0 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pyflakes >=0.6.0  :  2.0.0 (OK)
pygments >=2.0    :  2.3.1 (OK)
pylint >=0.25     :  2.2.2 (OK)
qtconsole >=4.2.0 :  4.4.3 (OK)
rope >=0.9.4      :  0.11.0 (OK)
sphinx >=0.6.6    :  1.8.2 (OK)
sympy >=0.7.3     :  None (NOK)
jennirinker commented 5 years ago

A note on the structure of the package:

pyconturb/
---| __init__.py
---| ...
---| io/
-------| __init__.py
-------| hawc2.py
-------| ...
ccordoba12 commented 5 years ago

Thanks for reporting. I don't understand the cause of this error but we'll try to figure it out.

@dalthviz, please follow @jennirinker instructions to see if you're able to reproduce this error.

dalthviz commented 5 years ago

@ccordoba12 I tried to reproduce this but no error is shown:

frozen

@jennirinker could you provide us the list of packages of your env with pyconturb and Spyder? Are there any important differences between the packages in those envs that you are using and these ones?:

Spyder

alabaster                 0.7.12                   py36_0
asn1crypto                0.24.0                   py36_0
astroid                   2.1.0                    py36_0
atomicwrites              1.3.0                    py36_1
attrs                     19.1.0                   py36_1
babel                     2.6.0                    py36_0
backcall                  0.1.0                    py36_0
blas                      1.0                         mkl
bleach                    3.1.0                    py36_0
ca-certificates           2019.1.23                     0
certifi                   2019.3.9                 py36_0
cffi                      1.11.5           py36h74b6da3_1
chardet                   3.0.4                    py36_1
cloudpickle               0.7.0                      py_0
colorama                  0.4.1                    py36_0
coverage                  4.5.3            py36he774522_0
cryptography              2.3.1            py36h74b6da3_0
cycler                    0.10.0           py36h009560c_0
decorator                 4.3.2                    py36_0
docutils                  0.14             py36h6012d8f_0
entrypoints               0.3                      py36_0
flaky                     3.5.3                    py36_0
freetype                  2.9.1                ha9979f8_1
icc_rt                    2019.0.0             h0cc432a_1
icu                       58.2                 ha66f8fd_1
idna                      2.8                      py36_0
imagesize                 1.1.0                    py36_0
intel-openmp              2019.1                      144
ipykernel                 5.1.0            py36h39e3cac_0
ipython                   7.2.0            py36h39e3cac_0
ipython_genutils          0.2.0            py36h3c5d0ee_0
isort                     4.3.4                    py36_0
jedi                      0.13.2                   py36_0
jinja2                    2.10                     py36_0
jpeg                      9b                   hb83a4c4_2
jsonschema                2.6.0            py36h7636477_0
jupyter_client            5.2.4                    py36_0
jupyter_core              4.4.0                    py36_0
keyring                   18.0.0                   py36_0
kiwisolver                1.0.1            py36h6538335_0
lazy-object-proxy         1.3.1            py36hfa6e2cd_2
libpng                    1.6.36               h2a8f88b_0
libsodium                 1.0.16               h9d3ae62_0
libtiff                   4.0.10               hb898794_2
markupsafe                1.1.0            py36he774522_0
matplotlib                2.2.2            py36had4c4a9_2
mccabe                    0.6.1                    py36_1
mistune                   0.8.4            py36he774522_0
mkl                       2019.1                      144
mkl_fft                   1.0.10           py36h14836fe_0
mkl_random                1.0.2            py36h343c172_0
mock                      2.0.0            py36h9086845_0
more-itertools            6.0.0                    py36_0
nbconvert                 5.3.1                    py36_0
nbformat                  4.4.0            py36h3a5bc1b_0
numpy                     1.15.4           py36h19fb1c0_0
numpy-base                1.15.4           py36hc3f5095_0
numpydoc                  0.8.0                    py36_0
olefile                   0.46                     py36_0
openssl                   1.0.2r               he774522_0
packaging                 19.0                     py36_0
pandoc                    2.2.3.2                       0
pandocfilters             1.4.2                    py36_1
parso                     0.3.2                    py36_0
pbr                       5.1.3                      py_0
pickleshare               0.7.5                    py36_0
pillow                    5.4.1            py36hdc69c19_0
pip                       19.0.1                   py36_0
pluggy                    0.9.0                    py36_0
prompt_toolkit            2.0.8                      py_0
psutil                    5.5.0            py36he774522_0
py                        1.8.0                    py36_0
pycodestyle               2.5.0                    py36_0
pycparser                 2.19                     py36_0
pyflakes                  2.1.0                    py36_0
pygments                  2.3.1                    py36_0
pylint                    2.2.2                    py36_0
pyopenssl                 19.0.0                   py36_0
pyparsing                 2.3.1                    py36_0
pyqt                      5.6.0            py36ha878b3d_6
pysocks                   1.6.8                    py36_0
pytest                    4.0.2                    py36_0
pytest-cov                2.6.1                    py36_0
pytest-mock               1.10.1                   py36_0
pytest-qt                 3.2.2                     <pip>
python                    3.6.8                h9f7ef89_1
python-dateutil           2.7.5                    py36_0
pytz                      2018.9                   py36_0
pywin32                   223              py36hfa6e2cd_1
pyzmq                     17.1.2           py36ha925a31_2
qt                        5.6.2           vc14h6f8c307_12
qtawesome                 0.5.7                    py36_1
qtconsole                 4.4.3                    py36_0
qtpy                      1.6.0                      py_0
requests                  2.21.0                   py36_0
rope                      0.11.0                   py36_0
setuptools                40.8.0                   py36_0
sip                       4.18.1           py36h6538335_2
six                       1.12.0                   py36_0
snowballstemmer           1.2.1            py36h763602f_0
sphinx                    1.8.4                    py36_0
sphinxcontrib             1.0                      py36_1
sphinxcontrib-websupport  1.1.0                    py36_1
spyder                    3.3.4                    py36_0
spyder-kernels            0.4.4                    py36_0
sqlite                    3.26.0               he774522_0
testpath                  0.4.2                    py36_0
tk                        8.6.8                hfa6e2cd_0
tornado                   5.1.1            py36hfa6e2cd_0
traitlets                 4.3.2            py36h096827d_0
typed-ast                 1.3.1            py36he774522_0
urllib3                   1.24.1                   py36_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.15.26706          h3a45250_0
wcwidth                   0.1.7            py36h3d5aa90_0
webencodings              0.5.1                    py36_1
wheel                     0.32.3                   py36_0
win_inet_pton             1.0.1                    py36_1
wincertstore              0.2              py36h7fe50ca_0
wrapt                     1.11.1           py36he774522_0
xz                        5.2.4                h2fa13f4_4
zeromq                    4.3.1                h33f27b4_3
zlib                      1.2.11               h62dcd97_3
zstd                      1.3.7                h508b16e_0

Pyconturb kernel

alabaster                 0.7.12                   py36_0
asn1crypto                0.24.0                   py36_0
astroid                   2.2.5                    py36_0
attrs                     19.1.0                   py36_1
babel                     2.6.0                    py36_0
backcall                  0.1.0                    py36_0
bleach                    3.1.0                    py36_0
ca-certificates           2019.1.23                     0
certifi                   2019.3.9                 py36_0
cffi                      1.12.3           py36h7a1dbc1_0
chardet                   3.0.4                    py36_1
cloudpickle               0.8.1                      py_0
colorama                  0.4.1                    py36_0
cryptography              2.6.1            py36h7a1dbc1_0
decorator                 4.4.0                    py36_1
defusedxml                0.6.0                      py_0
docutils                  0.14             py36h6012d8f_0
entrypoints               0.3                      py36_0
icu                       58.2                 ha66f8fd_1
idna                      2.8                      py36_0
imagesize                 1.1.0                    py36_0
ipykernel                 5.1.0            py36h39e3cac_0
ipython                   7.5.0            py36h39e3cac_0
ipython_genutils          0.2.0            py36h3c5d0ee_0
isort                     4.3.17                   py36_0
jedi                      0.13.3                   py36_0
jinja2                    2.10.1                   py36_0
jpeg                      9b                   hb83a4c4_2
jsonschema                3.0.1                    py36_0
jupyter_client            5.2.4                    py36_0
jupyter_core              4.4.0                    py36_0
keyring                   18.0.0                   py36_0
lazy-object-proxy         1.3.1            py36hfa6e2cd_2
libpng                    1.6.37               h2a8f88b_0
libsodium                 1.0.16               h9d3ae62_0
markupsafe                1.1.1            py36he774522_0
mccabe                    0.6.1                    py36_1
mistune                   0.8.4            py36he774522_0
nbconvert                 5.5.0                      py_0
nbformat                  4.4.0            py36h3a5bc1b_0
numpy                     1.16.3                    <pip>
numpydoc                  0.9.1                      py_0
openssl                   1.1.1b               he774522_1
packaging                 19.0                     py36_0
pandas                    0.24.2                    <pip>
pandoc                    2.2.3.2                       0
pandocfilters             1.4.2                    py36_1
parso                     0.4.0                      py_0
pickleshare               0.7.5                    py36_0
pip                       19.1                     py36_0
prompt_toolkit            2.0.9                    py36_0
psutil                    5.6.2            py36he774522_0
pycodestyle               2.5.0                    py36_0
pyconturb                 2.0                       <pip>
pycparser                 2.19                     py36_0
pyflakes                  2.1.1                    py36_0
pygments                  2.3.1                    py36_0
pylint                    2.3.1                    py36_0
pyopenssl                 19.0.0                   py36_0
pyparsing                 2.4.0                      py_0
pyqt                      5.9.2            py36h6538335_2
pyrsistent                0.14.11          py36he774522_0
pysocks                   1.6.8                    py36_0
python                    3.6.8                h9f7ef89_7
python-dateutil           2.8.0                    py36_0
pytz                      2019.1                     py_0
pywin32                   223              py36hfa6e2cd_1
pyzmq                     18.0.0           py36ha925a31_0
qt                        5.9.7            vc14h73c81de_0
qtawesome                 0.5.7                    py36_1
qtconsole                 4.4.3                    py36_0
qtpy                      1.7.0                    py36_1
requests                  2.21.0                   py36_0
rope                      0.14.0                     py_0
setuptools                41.0.1                   py36_0
sip                       4.19.8           py36h6538335_0
six                       1.12.0                   py36_0
snowballstemmer           1.2.1            py36h763602f_0
sphinx                    2.0.1                      py_0
sphinxcontrib-applehelp   1.0.1                      py_0
sphinxcontrib-devhelp     1.0.1                      py_0
sphinxcontrib-htmlhelp    1.0.2                      py_0
sphinxcontrib-jsmath      1.0.1                      py_0
sphinxcontrib-qthelp      1.0.2                      py_0
sphinxcontrib-serializinghtml 1.1.3
spyder                    3.3.4                    py36_0
spyder-kernels            0.4.4                    py36_0
sqlite                    3.28.0               he774522_0
testpath                  0.4.2                    py36_0
tornado                   6.0.2            py36he774522_0
traitlets                 4.3.2            py36h096827d_0
typed-ast                 1.3.4            py36he774522_0
urllib3                   1.24.2                   py36_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.15.26706          h3a45250_4
wcwidth                   0.1.7            py36h3d5aa90_0
webencodings              0.5.1                    py36_1
wheel                     0.33.1                   py36_0
win_inet_pton             1.1.0                    py36_0
wincertstore              0.2              py36h7fe50ca_0
wrapt                     1.11.1           py36he774522_0
zeromq                    4.3.1                h33f27b4_3
zlib                      1.2.11               h62dcd97_3
jennirinker commented 5 years ago

My conda list outputs are attached. Biggest difference is that the spyder kernel is 3.7, so all the package channels are different. Additionally, it looks like you installed the latest stable version of pyconturb from pip, and I'm running off a local editable installation. I think you might need to clone pyconturb and do an editable install:

conda env create --name pyconturb python=3.6
activate pyconturb
pip install spyder-kernels==0.*
git clone https://gitlab.windenergy.dtu.dk/rink/pyconturb.git
cd pyconturb
pip install -e .

spyder-env.txt pyconturb-env.txt

EDIT: forgot spyder-kernels

jennirinker commented 5 years ago

I did a test environment with pyconturb in a 3.7 environment, and the issue persists. Here is the environment packages for pyconturb with python 3.7.

pyconturb37-env.txt

ccordoba12 commented 5 years ago

Please do what @dalthviz did, i.e. installing everything with conda but pyconturb. And also install its stable version, not the Github one.

ccordoba12 commented 5 years ago

Closing because this is not an Spyder issue.