Python 3.5:我收到一个错误:“NameError:name'multiprocessing'未定义”

时间:2016-08-05 15:51:54

标签: python facebook multiprocessing

我收到错误:

    pool = multiprocessing.Pool(5)
NameError: name 'multiprocessing' is not defined

那么,如何修复呢?非常感谢你:))

from multiprocessing import Pool
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
from selenium import webdriver

if __name__ == '__main__':
    driver = webdriver.Firefox()
    driver.get("https://www.facebook.com/")
    driver.find_element_by_css_selector("#email").send_keys("myemail@gmail.com")
    driver.find_element_by_css_selector("#pass").send_keys("mypassword")
    driver.find_element_by_css_selector("#u_0_m").click()

    pool = multiprocessing.Pool(5)
    pool.map(friend_uid_list, uid_list)

3 个答案:

答案 0 :(得分:0)

您要导入Pool,而不是multiprocessing

from multiprocessing import Pool替换为import multiprocessing

答案 1 :(得分:0)

您尚未宣布多处理是什么。您还没有导入模块,只需从多处理导入。换句话说,多处理不在您的命名空间中,因此NameError。尝试导入整个模块,它应该可以工作。

import multiprocessing

否则,由于您导入了 Pool ,您只需编写:

pool = Pool(5)

答案 2 :(得分:0)

您已import Pool multiprocessing。所以你需要替换

pool = multiprocessing.Pool(5)

通过

pool = Pool(5)