简体   繁体   English

Visual Studio代码python导入和类

[英]Visual-Studio-Code python imports and classes

When using VS Code, I noticed things like... from multiprocessing import Pool, Value 当使用VS Code时,我注意到诸如...从多处理导入池,值

Do not work... I can from multiprocessing import pool, then dig into that to get the Pool class, but even if it is valid Python, I cannot seem to import the class directly with intellisense. 不起作用...我可以从多处理导入池中进行挖掘,然后深入研究以获得Pool类,但是即使它是有效的Python,我似乎也无法直接使用intellisense导入该类。

In addition, because it doesn't understand why I'm just importing a class, all the rest the autocomplete falls right on its face. 另外,由于它不理解为什么我只是要导入一个类,因此自动完成的其余所有功能都应运而生。 Even if it is valid code. 即使是有效的代码。

I've searched for settings, messed with some knobs, and editor tweaks, but I just cannot get VSCode to import classes from any module. 我已经搜索了设置,弄乱了一些旋钮,并对编辑器进行了调整,但我只是无法让VSCode从任何模块中导入类。 Seems that the class isn't in multiprocessing but a package below it, and it isn't drilling in. 似乎该类不在多进程中,而是在它下面的一个包中,并且没有深入。

You need to use 您需要使用

from multiprocessing.pool import Pool 从multiprocessing.pool导入池

Pool doesn't exist in the multiprocessing package but it exists in the pool subpackage under multiprocessing. 池在多处理程序包中不存在,但在多处理下的池子包中存在。 The directory structure is 目录结构是

multiprocessing/
    __init__.py
    pool.py

When you do 当你做

from multiprocessing import pool 从多处理导入池

You are actually trying to import from __init__.py which doesn't have the Pool class, pool.py has the Pool class. 您实际上是在尝试从不具有Pool类的__init__.py导入,pool.py具有Pool类。 Hope this helps. 希望这可以帮助。

reference - Python multiprocessing source code on github 参考-github上的Python多处理源代码

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

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