Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named multiprocessing.pool #353

Closed
Stroicomte opened this issue Feb 1, 2018 · 15 comments · Fixed by #627
Closed

ModuleNotFoundError: No module named multiprocessing.pool #353

Stroicomte opened this issue Feb 1, 2018 · 15 comments · Fixed by #627

Comments

@Stroicomte
Copy link

Hi,
i'm trying to use cx_freeze with sklearn package.
I use the multiprocessing.pool package and so far, tell cx_freeze to import by putting it on the package list in my setup.py. But, i've got an error when launching my .exe

Here is the log :

C:\Users\SR1689CN\Documents\Winpython\WinPython-64bit-3.6.3.0Qt5\python-3.6.3.am
d64>C:\Users\SR1689CN\Documents\Winpython\WinPython-64bit-3.6.3.0Qt5\python-3.6.
3.amd64\build\exe.win-amd64-3.6\main.exe
Traceback (most recent call last):
  File "C:\Users\SR1689CN\Documents\Winpython\WinPython-64bit-3.6.3.0Qt5\python-
3.6.3.amd64\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in
 run
    module.run()
  File "C:\Users\SR1689CN\Documents\Winpython\WinPython-64bit-3.6.3.0Qt5\python-
3.6.3.amd64\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run

    exec(code, m.__dict__)
  File "C:\Users\SR1689CN\Documents\Python\AD\Application\main.py", line 11, in
<module>
    from multiprocessing.pool import Pool
ModuleNotFoundError: No module named 'multiprocessing.pool'

And here is my setup.py :

# -*- coding: utf-8 -*-
"""
Created on Wed Jan 31 16:44:19 2018

"""

import sys, os
from cx_Freeze import setup, Executable
 
#############################################################################
# preparation des options
 
# chemins de recherche des modules
# ajouter d'autres chemins (absolus) si necessaire: sys.path + ["chemin1", "chemin2"]
path = sys.path
 
# options d'inclusion/exclusion des modules
includes = [ "numpy", "PyQt5", "sklearn", "pandas", "operator", "datetime", "multiprocessing", "multiprocessing.pool" ] 
excludes = []
packages = [ "numpy", "PyQt5", "sklearn", "pandas", "operator", "datetime", "multiprocessing", "multiprocessing.pool" ] 
 
# copier les fichiers non-Python et/ou repertoires et leur contenu:
includefiles = []
 
if sys.platform == "win32":
    pass
    # includefiles += [...] : ajouter les recopies specifiques à Windows
elif sys.platform == "linux2":
    pass
    # includefiles += [...] : ajouter les recopies specifiques à Linux
else:
    pass
    # includefiles += [...] : cas du Mac OSX non traite ici
 
# pour que les bibliotheques binaires de /usr/lib soient recopiees aussi sous Linux
binpathincludes = []
if sys.platform == "linux2":
    binpathincludes += ["/usr/lib"]
 
# niveau d'optimisation pour la compilation en bytecodes
optimize = 0
 
# si True, n'affiche que les warning et les erreurs pendant le traitement cx_freeze
silent = True
 
# construction du dictionnaire des options
options = {"path": path,
           "includes": includes,
           "excludes": excludes,
           "packages": packages,
           "include_files": includefiles,
           "bin_path_includes": binpathincludes,
           "optimize": optimize,
           "silent": silent
           }
 
# pour inclure sous Windows les dll system de Windows necessaires
if sys.platform == "win32":
    options["include_msvcr"] = True
 
#############################################################################
# preparation des cibles
base = None
if sys.platform == "win32":
    base = "Win32GUI"  # pour application graphique sous Windows
    #base = "Console" # pour application en console sous Windows
 
 
cible_1 = Executable(
    script=r'C:\Users\SR1689CN\Documents\Python\AD\Application\main.py',
    base=base
    )


os.environ['TCL_LIBRARY']=r'C:\Users\SR1689CN\Documents\Winpython\WinPython-64bit-3.6.3.0Qt5\python-3.6.3.amd64\tcl\tcl8.6'
os.environ['TK_LIBRARY']=r'C:\Users\SR1689CN\Documents\Winpython\WinPython-64bit-3.6.3.0Qt5\python-3.6.3.amd64\tcl\tk8.6'

 
#############################################################################
# creation du setup
setup(
    name="AD²",
    version="1.00",
    description="AD²",
    author="SR1689CN",
    options={"build_exe": options},
    executables=[cible_1]
    )

Could you please give me any advice on what's wrong ?

Thx

@Stroicomte
Copy link
Author

Turned out, i found the solution.
By renaming Pool.pyc by pool.pyc in the multiprocessing folder processed by cx_freeze.

@niecore
Copy link

niecore commented Mar 28, 2018

Any idea for a non manual fix?

Edit::

for filename in os.listdir ("build"):
      os.rename("build\\" + filename + "\lib\multiprocessing\Pool.pyc",
                  "build\\" + filename + "\lib\multiprocessing\pool.pyc")

@mx2048
Copy link

mx2048 commented Apr 19, 2018

In my case, the lib\multiprocessing directory was empty. So I put pool.py inside and so it works.

@Dishcreate
Copy link

Dishcreate commented Sep 11, 2018

This one work for me as well.
By renaming Pool.pyc to pool.pyc in the multiprocessing folder processed by cx_freeze.

@jpegcoma
Copy link

jpegcoma commented Dec 8, 2018

Any ideas if I still getting this error??

Microsoft Windows [Version 10.0.17134.407]
(c) Корпорация Майкрософт (Microsoft Corporation), 2018. Все права защищены.

C:\Users\jpegcoma\VK\1\1\build_windows>tryingdoexe.exe
Traceback (most recent call last):
  File "C:\Users\jpegcoma\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\jpegcoma\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "tryingdoexe.py", line 419, in <module>
  File "tryingdoexe.py", line 345, in main
  File "tryingdoexe.py", line 57, in get_stuf_from_url
  File "C:\Users\jpegcoma\Anaconda3\lib\multiprocessing\dummy\__init__.py", line 116, in Pool
    from ..pool import ThreadPool
ModuleNotFoundError: No module named 'multiprocessing.pool'

"\lib\multiprocessing\pool.pyc" - this one is written like that "pool.pyc"

But still not working

`from cx_Freeze import setup, Executable
import os

executables = [Executable('tryingdoexe.py')]

includes = ['re', "idna.idnadata", 'multiprocessing', 'multiprocessing.dummy','multiprocessing.pool']
excludes = ['PyQt5','ctypes','asn1crypto','lib2to3', 'tkinter', 'zope', 'zmq',
           'xmlrpc', 'xml', 'win32com', 'win_unicode_console', 'wcwidth', 'unittest',
           'twisted', 'traitlets', 'tornado', 'sqlite3', 'sqlalchemy', 'sphinxcontrib',
           'sphinx', 'setuptools', 'scipy', 'pywin', 'pytz', 'pyreadline', 
           'pygments', 'pydoc_data', 'pycparser', 'psutil', 'prompt_toolkit',
           'pluggy', 'pkg_resources', 'pathlib2', 'parso', 'packaging', 'OpenSSL', 
           'numpydoc', 'numpy', 'notebook', 'nose', 'nbformat', 'nbconvert', 'more_itertools',
           'mkl_fft', 'matplotlib', 'markupsafe', 'jupyter_core', 'jupyter_client',
           'jsonschema', 'jinja2', 'jedi', 'ipython_genutils', 'IPython', 'ipykernel',
           'incremental', 'docutils', 'dateutil',
           'curses', 'cryptography', 'concurrent', 'colorama',
           'cloudpickle', 'chardet', 'cffi', 'certifi', 'backports', 'backcall',
           'babel', 'attr', 'atomicwrites', 'asyncio', 'adodbapi', '_pytest']
options = {
    'build_exe': {
        'excludes': excludes,
        'includes': includes,
        'build_exe': 'build_windows',
    }
}

setup(name="post_to_VK",
     version = '0.1',
     description='post images from instagram to vk',
     executables = executables,
     options = options)`

Found what I was doing wrong!
It is working now
Thanks for thistred

@Malyaj
Copy link

Malyaj commented Dec 10, 2018

@jpegcoma could you please share what you did that solved the issue? I am facing a similar issue with bundling sklearn with cx freeze.

I tested the rest of the application - it works fine, but with sklearn it shows errors - pool.pyc, scipy.spatial.ckdtree etc..

Any help would be appreciated.

@jpegcoma
Copy link

@Malyaj, actually I did exactly what was said in upper answers, bro.
First, I misunderstood where the "Pool" should be changed to "poll".

Let Cx_Freeze work, it will make the 'build' folder, go to 'multiprocessing' in this folder and rename 'Pool' to 'pool' in the folder.

@swisnieski
Copy link

This fixes the issue in the build folder, but the problem remains if building/distributing using bdist_msi. Any solution there?

@Sieboldianus
Copy link

Sieboldianus commented May 10, 2019

I added the following lines to the end of my cx_freeze.py to automatically rename the file after build:

BUILD_PATH_POOL = (
    Path.cwd() / 'build' / BUILD_NAME /
    'lib' / 'multiprocessing')
Path(BUILD_PATH_POOL / 'Pool.pyc').rename(
    BUILD_PATH_POOL / 'pool.pyc')

(Note: the path format requires from pathlib import Path)

This has worked for me for a while now.

@Wieslaw68
Copy link

Here is the ready corrected cx-freeze file. According to your instructions.
Works in Win7-32 bit and Python 3.6.5

@rk-exxec
Copy link

This fixes the issue in the build folder, but the problem remains if building/distributing using bdist_msi. Any solution there?

Did somebody fix this? I am stuck on this problem.
The name of the pool.py is lowercase in my python folder, why is it even in uppercase in the build folder after cx_Freeze?

@swisnieski
Copy link

This fixes the issue in the build folder, but the problem remains if building/distributing using bdist_msi. Any solution there?

Did somebody fix this? I am stuck on this problem.
The name of the pool.py is lowercase in my python folder, why is it even in uppercase in the build folder after cx_Freeze?

I got it figured out, actually. Go into your Python installation directory > Lib > site-packages > cx_Freeze. You want to edit hooks.py by adding the line

finder.ExcludeModule("multiprocessing.Pool")

to the 'initialize' function, right after the other invocations of finder.ExcludeModule().

Hope that helps. Now running cx_Freeze with bdist_msi works just fine, for me at least.

@rk-exxec
Copy link

You want to edit hooks.py by adding the line
finder.ExcludeModule("multiprocessing.Pool")
to the 'initialize' function, right after the other invocations of finder.ExcludeModule().

Just adding 'multiprocessing.Pool' to the excludes in the setup.py also seems to work just fine!
'excludes': ['multiprocessing.Pool']

@marcelotduarte
Copy link
Owner

marcelotduarte commented Mar 31, 2020

Can you test the PR? (only if you have a C compiler)

pip install -U git+https://github.com/anthony-tuininga/cx_Freeze.git@refs/pull/627/head

@rk-exxec
Copy link

Can you test the PR? (only if you have a C compiler)

pip install -U git+https://github.com/anthony-tuininga/cx_Freeze.git@refs/pull/627/head

Works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.