当我想在一个特定的文件夹中安装一个Python包(使用pip install-t),然后从该包中导入一个模块时,我遇到了一个错误。你知道吗
我在程序包的Github上发布了这个问题,结果发现我无法在某个文件夹中安装程序包;以这种方式安装程序包是不受支持的。你知道吗
Even without google collab, I can reproduce the import error when trying to install sklearn in some specific folder with pip install -t sklearnFolder then importing it as sklearnFolder.sklearn.manifold.
That is not a supported way of installing / using scikit-lean. One reason why it wouldn't work is that a few modules in scikit-learn use absolute imports (e.g. from sklearn import something) which will fail with such setup.
You should either install it with pip install or if you want to have it in some specific folder, clone the repo to that folder, then run pip install -e , in both cases it will be imported as sklearn.
从https://github.com/scikit-learn/scikit-learn/issues/11656
我不太明白这个解释。你知道吗
我觉得
from folderName.package import module
与相同
from package import module
因为它们都是绝对进口的。与中一样,它们都完全指定了导入模块的路径。所以我的理解有些偏差,但我不知道是什么。你知道吗
在导入中,不指定folderName作为包的前缀。如果包已安装或位于python路径中,则只需使用包名称即可导入。你知道吗
由于包位于/app/home/packages下,因此以下导入无效,因为您在文件夹名称前加了前缀。你知道吗
正确的导入方法是从实际的包中导入,该包具有包初始化\uu init \uuuuy.py。如果您在示例中看到,reservation folder有\uu init \uuuuuy.py。你知道吗
如果您想导入hotels下的子模块,那么您将以包作为前缀:
或者,您可以直接导入子模块,但在使用包时必须以其作为前缀:
相关问题 更多 >
编程相关推荐