我正在使用多处理和pathos编写一些python代码。我已经编写了一个小的测试程序来习惯使用multiprocessing,它在本地计算机上运行良好,但它拒绝在不同的集群上运行。
我得到以下错误:
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
病理和多处理模块都很明显:
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()
最佳答案
我是pathos
和multiprocess
的作者。我认为有两个可能的原因你找不到_multiprocess
。第一个,也是最常见的原因是,你没有一个C++编译器。multiprocessing
需要一个C++编译器,如果你在Windows上,你必须安装一个。见:https://wiki.python.org/moin/WindowsCompilers。第二个问题是,如果您处理PATH
等,它是如何安装的,这是一个PYTHONPATH
/prefix
问题,因此找不到它,但这是极少数情况。
关于python - Python Multiprocessing和Pathos:导入错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38788994/