ValueError: py.__spec__ is not set for pandas

  pandas, py2exe, python

I am trying to create an exe from below python script in file fact.py

import pandas as pd
df=pd.read_csv('C:py2exemyfile.csv')
print(df.dtypes)

and my setup.py

from distutils.core import setup

import py2exe
import pandas

setup(console=['fact.py'])

and in anaconda prompt, ran below code.

c:py2exe>python setup.py py2exe

and I am getting below error.

(base) c:py2exe>python setup.py py2exe
running py2exe
Traceback (most recent call last):
  File "setup.py", line 6, in <module>
    setup(console=['fact.py'])
  File "C:UsersuserAnaconda3libdistutilscore.py", line 148, in setup
    dist.run_commands()
  File "C:UsersuserAnaconda3libdistutilsdist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:UsersuserAnaconda3libdistutilsdist.py", line 985, in run_command
    cmd_obj.run()
  File "C:UsersuserAnaconda3libsite-packagespy2exedistutils_buildexe.py", line 192, in run
    self._run()
  File "C:UsersuserAnaconda3libsite-packagespy2exedistutils_buildexe.py", line 272, in _run
    builder.analyze()
  File "C:UsersuserAnaconda3libsite-packagespy2exeruntime.py", line 177, in analyze
    target.analyze(mf)
  File "C:UsersuserAnaconda3libsite-packagespy2exeruntime.py", line 78, in analyze
    modulefinder.run_script(self.script)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 62, in run_script
    self._scan_code(mod.__code__, mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 332, in _find_and_load
    self._load_module(spec, name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 364, in _load_module
    self._add_module(name, mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exedllfinder.py", line 263, in _add_module
    self.hook(mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exedllfinder.py", line 260, in hook
    mth(self, mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exehooks.py", line 585, in hook_pandas
    finder.import_hook("pandas._libs.tslibs.base")
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 272, in _find_and_load
    self._gcd_import(parent)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 272, in _find_and_load
    self._gcd_import(parent)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 272, in _find_and_load
    self._gcd_import(parent)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 272, in _find_and_load
    self._gcd_import(parent)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 109, in import_hook
    self._handle_fromlist(module, fromlist, caller)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 180, in _handle_fromlist
    self._gcd_import('{}.{}'.format(mod.__name__, x))
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 109, in import_hook
    self._handle_fromlist(module, fromlist, caller)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 180, in _handle_fromlist
    self._gcd_import('{}.{}'.format(mod.__name__, x))
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 109, in import_hook
    self._handle_fromlist(module, fromlist, caller)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 180, in _handle_fromlist
    self._gcd_import('{}.{}'.format(mod.__name__, x))
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 109, in import_hook
    self._handle_fromlist(module, fromlist, caller)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 180, in _handle_fromlist
    self._gcd_import('{}.{}'.format(mod.__name__, x))
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 109, in import_hook
    self._handle_fromlist(module, fromlist, caller)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 180, in _handle_fromlist
    self._gcd_import('{}.{}'.format(mod.__name__, x))
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 393, in _scan_code
    self._scan_code(c, mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 272, in _find_and_load
    self._gcd_import(parent)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 107, in import_hook
    module = self._gcd_import(name, package, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 107, in import_hook
    module = self._gcd_import(name, package, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 393, in _scan_code
    self._scan_code(c, mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 393, in _scan_code
    self._scan_code(c, mod)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 109, in import_hook
    self._handle_fromlist(module, fromlist, caller)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 180, in _handle_fromlist
    self._gcd_import('{}.{}'.format(mod.__name__, x))
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 348, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 386, in _scan_code
    self.safe_import_hook(name, mod, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 122, in safe_import_hook
    self.import_hook(name, caller, fromlist, level)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 104, in import_hook
    module = self._gcd_import(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 258, in _gcd_import
    return self._find_and_load(name)
  File "C:UsersuserAnaconda3libsite-packagespy2exemf34.py", line 303, in _find_and_load
    spec = importlib.util.find_spec(name, path)
  File "C:UsersuserAnaconda3libimportlibutil.py", line 111, in find_spec
    raise ValueError('{}.__spec__ is not set'.format(name)) from None
ValueError: py.__spec__ is not set

I have tried this in multiple systems and getting the same error. without pandas, its working fine.Please help me out here. Thanks in advance

Source: Python Questions

LEAVE A COMMENT