对 Python 很陌生。我想安装 python 的多处理模块。我正在使用 python 3.6 和 pip 版本 9.1。
我收到一个错误,这让我相信由于没有与 python 3 兼容的多处理模块,因此可能会发生以下错误。
$ pip3 install multiprocessing
Collecting multiprocessing
Using cached multiprocessing-2.6.2.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/8m/2fkldrg12lg0qzlhpm8yvyq00000gn/T/pip-build-dqdczlx9/multiprocessing/setup.py", line 94
所以,我使用安装模块的 pip install multiprocessing 安装了模块。我已经在 python 3 中编写了很多代码,所以我想使用它并且我正在使用我已配置为使用 python3 的 pycharm 编辑器。现在,如果我在编辑器中执行代码,它会抛出类似的错误
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/kkk/Desktop/testing/multiprocessing.py
Traceback (most recent call last):
File "/Users/testing/multiprocessing.py", line 11, in <module>
p = multiprocessing.Process(target=worker)
AttributeError: module 'multiprocessing' has no attribute 'Process'
Process finished with exit code 1
对于代码
import multiprocessing
def worker():
"""worker function"""
print ('Worker')
return
if __name__ == '__main__':
jobs = []
for i in range(5):
p = multiprocessing.Process(target=worker)
jobs.append(p)
p.start()
我能做些什么来解决这个问题?
谢谢
原文由 Sam Thadhani 发布,翻译遵循 CC BY-SA 4.0 许可协议
从 Python 2.6 开始,
multiprocessing
是一个内置模块。它随 Python 一起提供,不需要特定的安装步骤。