Open IvarVirusiim opened 1 year ago
I have similar issue with this code:
import pyVmomi.vim as vim
print(vim.Task)
# Result (unexpected): AttributeError: module 'pyVmomi.vim' has no attribute 'Task'
While this equivalent-at-a-glance code works:
from pyVmomi import vim
print(vim.Task)
# Result (expected): <class 'pyVmomi.VmomiSupport.vim.Task'>
Furthermore, if e.g. import pyVmomi.vim
is called first, it breaks the module within that python runtime, for example:
import pyVmomi.vim
from pyVmomi import vim
print(vim.Task)
# Result (unexpected): AttributeError: module 'pyVmomi.vim' has no attribute 'Task'
If this is not easy to fix, I'd recommend adding something like raise ImportError('Use "from pyVmomi import vim" ...')
when module is imported via import X
, which should be detectable via same missing class-attribute lookups.
This way, at least it'd be clear what the issue is, as otherwise it looks like module and all example code for it is outdated or broken in current pip releases, as it tries to use no-longer-existant module attributes.
Describe the bug
When trying to import using PyCharm, using for example
VirtualMachine
, it importspyVmomi.vim.VirtualMachine
, but the correct import isvim.VirtualMachine
. This causes errors during runtime.Reproduction steps
Try to import some type automatically
Run the code and get error:
ImportError: cannot import name 'VirtualMachine' from 'pyVmomi.vim' (unknown location)
Expected behavior
Import would be correct:
from vim import VirtualMachine
Additional context
No response