Discussion:
[spyder] python package development in spyder: locally undefined variables
lueromat
2018-10-07 21:11:19 UTC
Permalink
Hi all,

I have written a python package with the following structure:

pkg/
__init__.py
script.py
utils.py

During development, I import the folders from my local repo to add new code
- not from site-packages. My problem is that after the local import, the
namespace from utils (containing helper functions) is not recognized in
script (containing core functionality, using helper functions). Therefore
spyder creates "undefined name" flags in my scripts, which is not helpful.
However, when I put import utils at the top of the script, it cannot get
imported and I get the error "No module named 'utils'.

Is there a way to tell spyder where these functions are defined without
breaking the package load?



My init file contains:

import pkgutil
import inspect


for loader, name, is_pkg in pkgutil.walk_packages(__path__):
module = loader.find_module(name).load_module(name)


for name, value in inspect.getmembers(module):
if name.startswith('__'):
continue


globals()[name] = value
__all__.append(name)

from pgk import script1, utils
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.
lueromat
2018-10-08 09:22:29 UTC
Permalink
Sorry, my bad, dumb noob error:

with
from pkg.utils import * in script.py it works fine.
Post by lueromat
Hi all,
pkg/
__init__.py
script.py
utils.py
During development, I import the folders from my local repo to add new
code - not from site-packages. My problem is that after the local import,
the namespace from utils (containing helper functions) is not recognized in
script (containing core functionality, using helper functions). Therefore
spyder creates "undefined name" flags in my scripts, which is not helpful.
However, when I put import utils at the top of the script, it cannot get
imported and I get the error "No module named 'utils'.
Is there a way to tell spyder where these functions are defined without
breaking the package load?
import pkgutil
import inspect
module = loader.find_module(name).load_module(name)
continue
globals()[name] = value
__all__.append(name)
from pgk import script1, utils
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.
Loading...