IPython consoles are not independent in terms of loading modules on Windows
See original GitHub issueIssue 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
(orpip
, 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?
- Create the following folder structure (with the content shown below):
one/one.py
one/utilities.py
two/two.py
two/utilities.py
- Open
one/one.py
andtwo/two.py
in the editor. - 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]:
- Output (which is correct) looks like this:
- Click the gear icon in the top-right of the console window and click “Open an IPython console”.
- Switch to the
two/two.py
tab in the editor. - Click the “Run” button.
- Exception is raised. If you do this in the opposite order (running
two.py
, opening a new console, runningone.py
), the exception is raised when runningone.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:
- Created 4 years ago
- Comments:10 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dalthviz, please try with the latest master of Spyder and spyder-kernels. PR spyder-ide/spyder-kernels#131 could have solved this problem.
Thanks for testing this @bcolsen!
@dalthviz, are you able to reproduce this on Windows?