1

I have a problem very similar to this one but I'm not about using gcloud but I'm trying to run pyqtdeploy.

I'm facing a strange problem: Running

>>> import importlib
>>> importlib.util.spec_from_file_location()

gives me

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'util'

..using Python3.8.6 with importlib-1.0.4 running on a Debian 10 +testing machine

while the exact same commands on Fedora 32 also running Python3.8.6 with importlib-1.0.4 let me use importlib.util:

>>> importlib.util.spec_from_file_location()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: spec_from_file_location() missing 1 required positional argument: 'name'

Why can the exact same module have an attribute on one system and not on the other?

And how do I make pyqtdeploy (and thus importlib.util) work as expected?

Background: I'm currently trying to run pyqtdeploy inside a Docker container but despite I'm using the same versions of Python and importlib it will run on the Fedora host but not inside the container..

frans
  • 8,868
  • 11
  • 58
  • 132
  • Importing a package doesn't automatically load its submodules. – user2357112 Nov 26 '20 at 19:39
  • sounds legit - but that doesn't answer my question - `pyqtdeploy` will work on one system and not on the other, despite I've installed the same versions of Python and `importlib`. So why do they behave differently? – frans Nov 26 '20 at 19:41
  • @frans Those version numbers don't really tell you anything because `importlib.util` may have already been imported by some other dependency before the `import importlib` line is executed. The fact is, your current code is not robust - you should use e.g. `import importlib.util` instead (i.e. EIBTI applies). To test things properly, put something like the following line before your import `print('\n'.join(key for key in sys.modules if key.startswith('importlib')))`. – ekhumoro Aug 13 '22 at 10:28

2 Answers2

0

user2357112 offers sound advice:

from importlib import util
0

Use instead e.g. from importlib import util as iutil and then iutil.spec_from_file_location().

cxxl
  • 4,939
  • 3
  • 31
  • 52