我正在使用multiprocessing&编写一些python代码。感伤。我已经编写了一个小测试程序来习惯使用多处理,它在我的本地机器上运行良好,但它拒绝在不同的集群上运行。
我收到以下错误:
Traceback (most recent call last):
File "./multi.py", line 116, in <module>
pool = pathos_multiprocessing.Pool(processes=pool_size,maxtasksperchild=1,)
File "/usr/local/lib/python3.4/dist-packages/multiprocess/pool.py", line 150, in __init__
self._setup_queues()
File "/usr/local/lib/python3.4/dist-packages/multiprocess/pool.py", line 243, in _setup_queues
self._inqueue = self._ctx.SimpleQueue()
File "/usr/local/lib/python3.4/dist-packages/multiprocess/context.py", line 110, in SimpleQueue
from .queues import SimpleQueue
File "/usr/local/lib/python3.4/dist-packages/multiprocess/queues.py", line 22, in <module>
import _multiprocess as _multiprocessing
ImportError: No module named '_multiprocess'
但是当我做了
pip3 list
两个悲and和多处理模块显然都存在:
multiprocess (0.70.4)
nbconvert (4.2.0)
nbformat (4.0.1)
nose (1.3.1)
notebook (4.2.0)
numpy (1.10.4)
oauthlib (0.6.1)
pathos (0.2.0)
为什么会发生这种情况的任何好主意都会受到欢迎!
小测试代码是:
#! /usr/bin/env python3
import pathos.multiprocessing as mp
import os
import random
class Pool_set:
def pool_fun(directory_name):
cwd=os.getcwd()
os.mkdir(str(directory_name))
directory=os.path.join(cwd,str(directory_name))
os.chdir(directory)
os.system('{}'.format('sleep '+str(directory_name)))
cwd2=os.getcwd()
print(cwd2)
test_file = open('test_file.out','w')
test_file.write(cwd2)
print("Finished in "+directory)
os.chdir(cwd)
if __name__ == '__main__':
config=[]
pool_set = Pool_set
for i in (random.sample(range(1,100),3)):
config.append(i)
pool_size = mp.cpu_count()
pool = mp.Pool(processes=pool_size,maxtasksperchild=1,)
pool_outputs = pool.map(pool_set.pool_fun,config)
pool.close()
pool.join()
答案 0 :(得分:0)
我是pathos
和multiprocess
作者。我认为有两个可能的原因你找不到_multiprocess
。第一个也是最常见的原因是你没有C ++编译器。 multiprocessing
需要一个C ++编译器,如果你在Windows上,你必须安装一个。见:https://wiki.python.org/moin/WindowsCompilers。第二个问题是,由于PATH
/ PYTHONPATH
如果您遇到prefix
等问题而导致安装问题,因此无法找到它,但这是极少数情况。