user3373322 user3373322 - 3 months ago 19
Python Question

Python 3.5: I am getting an error: "NameError: name 'multiprocessing' is not defined"

I am getting an error:

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


So, how to fix it ? Thank you very much :)

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)

Answer

You haven't declared what multiprocessing is. You haven't imported the module either, you just imported Pool from multiprocessing. In other words, multiprocessing is not in your namespace, hence NameError. Try import the whole module and it should work.

import multiprocessing

Otherwise, since you imported Pool, you could just write:

pool = Pool(5)
Comments