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.

IPython consoles are not independent in terms of loading modules on Windows

See original GitHub issue

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

If you open a second ipython console and run a script that imports a local file that shares its filename with a module imported by the first ipython console, the import fails.

What steps reproduce the problem?

  1. Create the following folder structure (with the content shown below):
    • one/one.py
    • one/utilities.py
    • two/two.py
    • two/utilities.py
  2. Open one/one.py and two/two.py in the editor.
  3. With one/one.py open, click the “Run” button.
    • Output (which is correct) looks like this:
      In [1]: runfile('C:/spydertest/one/one.py', wdir='C:/spydertest/one')
      Utility 1
      
      In [2]: 
      
  4. Click the gear icon in the top-right of the console window and click “Open an IPython console”.
  5. Switch to the two/two.py tab in the editor.
  6. Click the “Run” button.
  7. Exception is raised. If you do this in the opposite order (running two.py, opening a new console, running one.py), the exception is raised when running one.py instead.

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

Expected output:

In [1]: runfile('C:/spydertest/two/two.py', wdir='C:/spydertest/two')
Utility 2

In [2]: 

Actual output:

In [1]: runfile('C:/spydertest/two/two.py', wdir='C:/spydertest/two')
Traceback (most recent call last):

  File "<ipython-input-1-9cf34275bbc9>", line 1, in <module>
    runfile('C:/spydertest/two/two.py', wdir='C:/spydertest/two')

  File "c:\applications\development\languages\python\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "c:\applications\development\languages\python\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/spydertest/two/two.py", line 1, in <module>
    from utilities import two_utility

ImportError: cannot import name 'two_utility' from 'utilities' (C:\spydertest\one\utilities.py)


In [2]: 

Files used to demonstrate issue:

one/one.py:

from utilities import one_utility

print(one_utility())

one/utilities.py:

def one_utility():
    return "Utility 1"

two/two.py:

from utilities import two_utility

print(two_utility())

two/utilities.py:

def two_utility():
    return "Utility 2"

Paste Traceback/Error Below (if applicable)

See above.

Versions

  • Spyder version: 3.3.6
  • Python version: 3.7.1 64-bit
  • Qt version: 5.6.2
  • PyQt version: 5.6
  • Operating System name/version: Windows 10

Dependencies

IPython >=4.0     :  7.7.0 (OK)
cython >=0.21     :  0.29.12 (OK)
jedi >=0.9.0      :  0.13.3 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
nbconvert >=4.0   :  5.5.0 (OK)
numpy >=1.7       :  1.16.4 (OK)
pandas >=0.13.1   :  0.25.0 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pyflakes >=0.6.0  :  2.1.1 (OK)
pygments >=2.0    :  2.4.2 (OK)
pylint >=0.25     :  2.3.1 (OK)
qtconsole >=4.2.0 :  4.5.2 (OK)
rope >=0.9.4      :  0.14.0 (OK)
sphinx >=0.6.6    :  2.1.2 (OK)
sympy >=0.7.3     :  1.4 (OK)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ccordoba12commented, Aug 19, 2019

@dalthviz, please try with the latest master of Spyder and spyder-kernels. PR spyder-ide/spyder-kernels#131 could have solved this problem.

1reaction
ccordoba12commented, Aug 19, 2019

Thanks for testing this @bcolsen!

@dalthviz, are you able to reproduce this on Windows?

Read more comments on GitHub >

github_iconTop Results From Across the Web

python console tab completion not working in windows
I came here looking for a solution that works with the cmd module on windows 10. pyreadline works well with the cmd module...
Read more >
IPython Console — Spyder 5 documentation
When working in an interactive session, Python only loads a module from its source file once, the first time it is imported. Spyder's...
Read more >
No Module Named Pandas – How To Fix - Data Independent
“no module named pandas” happens because because your current python environment cannot find the pandas library. Here's a list of the common reasons...
Read more >
Troubleshoot Python errors in Azure Functions - Microsoft Learn
"Exception: ModuleNotFoundError: No module named 'module_name'." This error occurs when a Python function app fails to load a Python module.
Read more >
Python Tutorial: subprocesses module - 2020 - BogoToBogo
We cannot use UNIX commands in our Python script as if they were Python code. For example, echo name is causing a syntax...
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