attributeerror python_python多处理:AttributeError:无法获取属性“...

在尝试使用多进程按名称预测性别时遇到问题,代码在以前的机器上正常运行。错误发生在调用guess_gender函数时,提示无法在当前环境中找到该属性。已尝试在Anaconda的Python 3.6.1环境下运行,但问题依然存在,日志显示多个'AttributeError: Can't get attribute 'guess_gender' on'。
摘要由CSDN通过智能技术生成

我正在尝试运行一个简单的命令,使用多处理按名称猜测性别.这段代码适用于以前的机器,所以也许我的设置与它有关.

以下是我的多处理代码:

import sys

import gender_guesser.detector as gender

import multiprocessing

import time

d = gender.Detector()

def guess_gender (name):

n = name.title() # make first letter upper case and the rest lower case

g = d.get_gender(n) # guess gender

return g

ls = ['john','joe','amamda','derick','peter','ashley','john','joe','amamda','derick','peter','ashley']

t=time.time()

results=[]

def callBack(x):

results.append(x)

pool = multiprocessing.Pool(processes=multiprocessing.cpu_count()-1, maxtasksperchild=1)

for n in ls:

print (n)

pool.apply_async(guess_gender,args=[n],callback=callBack)

pool.close()

pool.join()

results = pd.concat(results)

print(time.time()-t)

它只是运行,不做任何事情.在我的cmd窗口中,我在错误消息的末尾看到以下内容:

AttributeError: Can't get attribute 'guess_gender' on

我在Anaconda上运行python版本3.6.1:

import sys

print(sys.version)

3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)]

更新:仍然无法让它工作.下面是我运行提供的代码时的整个cmd日志.我很感激您的任何想法!

C:\Users\ywu\Google Drive>jupyter notebook

[I 10:13:43.954 NotebookApp] Serving notebooks from local directory: C:\Users\ywu\Google Drive

[I 10:13:43.954 NotebookApp] 0 active kernels

[I 10:13:43.955 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=255a5c0c9af337a1c2187feb63f1c426fb903e5929a0b2f0

[I 10:13:43.956 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

[C 10:13:43.959 NotebookApp]

Copy/paste this URL into your browser when you connect for the first time,

to login with a token:

http://localhost:8888/?token=255a5c0c9af337a1c2187feb63f1c426fb903e5929a0b2f0

[I 10:13:44.264 NotebookApp] Accepting one-time-token-authenticated connection from ::1

[W 10:13:44.319 NotebookApp] 404 GET /api/kernels/aceb78ee-73e4-4481-9993-63e5ee8f72cb/channels?session_id=AEA3C6B2B0A440FC84FF3BAF5F5CB615 (127.0.0.1): Kernel does not exist: aceb78ee-73e4-4481-9993-63e5ee8f7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值