conda update spyder (or pip, if not using Anaconda)jupyter qtconsole (if console-related)spyder --resetIf 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.
one/one.pyone/utilities.pytwo/two.pytwo/utilities.pyone/one.py and two/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]:
two/two.py tab in the editor.two.py, opening a new console, running one.py), the exception is raised when running one.py 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]:
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"
See above.
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)
Please add empty __init__.py files to both your one and two directories to make them proper Python packages and try again.
I've added the empty __init__.py files but it made no difference to the outcome.
I wouldn't expect to have to have __init__.py files as this isn't a python module, this is an application (with one.py as the entry point). I wouldn't usually have an __init__.py in this situation even in python 2.7, but in python 3 the files aren't required anyway: quoting PEP 420:
Allowing implicit namespace packages means that the requirement to provide an
__init__.pyfile can be dropped completely,
I can't reproduce this using latest master on linux.
@abudden Are you able to see if this is still a problem on syder4 beta4?
Thanks for testing this @bcolsen!
@dalthviz, are you able to reproduce this on Windows?
@ccordoba12 I was able to reproduce this on Windows using Spyder 3.3.6
Main while @abudden a work around you could try is to not use the same name for the utilities file. I tested renaming them to one_utilities.py and two_utilities.py and worked for me.
@dalthviz, please try with the latest master of Spyder and spyder-kernels. PR spyder-ide/spyder-kernels#131 could have solved this problem.
@ccordoba12 testing with master of Spyder and Spyder-kernels I get the same error:
runfile('C:/Users/Daniel/Documents/Spyder/foo_folder/one/one.py', wdir='C:/Users/Daniel/Documents/Spyder/foo_folder/one')
Traceback (most recent call last):
File "<ipython-input-1-a6f57d3c5a2f>", line 1, in <module>
runfile('C:/Users/Daniel/Documents/Spyder/foo_folder/one/one.py', wdir='C:/Users/Daniel/Documents/Spyder/foo_folder/one')
File "c:\users\daniel\documents\spyder\spyder-kernels\spyder_kernels\customize\spydercustomize.py", line 890, in runfile
execfile(filename, namespace)
File "c:\users\daniel\documents\spyder\spyder-kernels\spyder_kernels\customize\spydercustomize.py", line 116, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Daniel/Documents/Spyder/foo_folder/one/one.py", line 1, in <module>
from utilities import one_utility
ImportError: cannot import name 'one_utility' from 'utilities' (C:\Users\Daniel\Documents\Spyder\foo_folder\two\utilities.py)
@dalthviz, are you able to reproduce this in IPython terminal or in qtconsole?
@ccordoba12 I was unable to reproduce this in QtConsole executing the files with %run. Also, when using %run inside Spyder it works as expected
@bcolsen Apologies for going quiet for a few days, I'm afraid I haven't been able to test on the latest spyder as I've been fighting zscaler and then conda issues and have been completely unable to update anything. It sounds like @dalthviz has reproduced this with the latest version (and yes @dalthviz, I'm already using that workaround), so at least it's not entirely dependent on me overcoming conda issues.