简体   繁体   English

无法从已安装和导入的模块中导入类

[英]Can't import class from installed and imported module

I'm using Python 3.6 on windows, trying to get the py_mstr module installed so I can interact with a MicroStrategy web portal 我在Windows上使用Python 3.6,试图安装py_mstr模块,以便可以与MicroStrategy Web门户进行交互

I downloaded and installed the module by running it's "setup.py" and it appears to have properly installed it to to C:...\\Python36-32\\Lib\\site-packages 我通过运行模块“ setup.py”下载并安装了该模块,它似乎已正确将其安装到C:... \\ Python36-32 \\ Lib \\ site-packages

I can import the module properly, but when I try to import a class, it returns an error 我可以正确导入模块,但是当我尝试导入类时,它将返回错误

>>> import py_mstr
>>> from py_mstr import MstrClient
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    from py_mstr import MstrClient
ImportError: cannot import name 'MstrClient'

I checked and py_mstr definitely contains the class "MstrClient" 我检查了一下,py_mstr肯定包含了“ MstrClient”类

I dug around and found that folder structure might have something to do with it, but I can't figure it out 我四处寻找,发现文件夹结构可能与它有关,但我无法弄清楚

Python35-32
    ...
    site-packages
        ...
        py_mstr
            __init__.py
            py_mstr.py
            _pycahce__
                __init__.cpython-36.pyc
                py_mstr.cpython-36.pyc

This package doesn't seem to support Python 3. You might be able to get it to run with 2to3, but if that doesn't work, you might have to run it on Python 2 instead. 该软件包似乎不支持Python3。您也许可以使其与2to3一起运行,但是如果不起作用,则可能必须在Python 2上运行它。

The specific Python 3 incompatibility causing your import failure is that py_mstr/__init__.py uses an implicit relative import to bring in the contents of py_mstr/py_mstr.py : 导致导入失败的特定Python 3不兼容性是py_mstr/__init__.py使用隐式相对导入来引入py_mstr/py_mstr.py的内容:

from py_mstr import *

Python 3 interprets this as importing * from the py_mstr package, not the py_mstr.py_mstr submodule. Python 3将此解释为从py_mstr包而不是py_mstr.py_mstr子模块导入* There may be other incompatibilities; 可能还存在其他不兼容性; I didn't do a thorough inspection. 我没有做彻底检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM