cx_Freeze icon indicating copy to clipboard operation
cx_Freeze copied to clipboard

FileNotFoundError when site module is imported

Open pbesson-invn opened this issue 5 years ago • 5 comments

Hello,

I am working in a virtualenv and I am trying to freeze (with cx_freeze 6.1) an application that uses tensorflow, but encounter the following exception when starting my exe:

Traceback (most recent call last):
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
    module.run()
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
    exec(code, {'__name__': '__main__'})
  File "app.py", line 13, in <module>
    from keras.callbacks import ModelCheckpoint, Callback
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\keras\backend\__init__.py", line 1, in <module>
    from .load_backend import epsilon
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\keras\backend\load_backend.py", line 90, in <module>
    from .tensorflow_backend import *
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\tensorflow\__init__.py", line 99, in <module>
    from tensorflow_core import *
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site-packages\tensorflow_core\__init__.py", line 24, in <module>
    import site as _site
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site.py", line 769, in <module>
    main()
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site.py", line 734, in main
    virtual_install_main_packages()
  File "C:\Users\pbesson\w\test_cx_freeze\venv\lib\site.py", line 556, in virtual_install_main_packages
    f = open(os.path.join(os.path.dirname(__file__), "orig-prefix.txt"))
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\pbesson\\w\\test_cx_freeze\\build\\exe.win-amd64-3.7\\lib\\library.zip\\orig-prefix.txt'

Is there any workaround to this issue ?

Thanks.

pbesson-invn avatar Jan 30 '20 16:01 pbesson-invn

Hi, I have the same error, Did anyone manage to solute it?

puse45 avatar Feb 12 '20 09:02 puse45

For this particular error, I think it is because virtualenv provides its own site.py.

You can try overwriting the site.py exported in the freezing package by the one from the original python:

# virtual env tweaks site.py causing error when imported in frozen script
# copy original module from python install
site_path = os.path.join(os.path.dirname(opcode.__file__), 'site.py')
sitebuiltins_path = os.path.join(os.path.dirname(opcode.__file__), '_sitebuiltins.py')

include_files = [
    (site_path, 'lib/site.py'),
    (sitebuiltins_path, 'lib/_sitebuiltins.py'),
]

I did that without being sure it is the proper fix. Anyhow, I still got other import error I am still trying to workaround...

pbesson-invn avatar Feb 12 '20 09:02 pbesson-invn

Still getting the some error, can you please share your setup.py file @pbesson-invn

puse45 avatar Feb 12 '20 10:02 puse45

@puse45 @pbesson-invn cx-freeze is built with Py_NoSiteFlag set to 1 See the implications at: https://docs.python.org/3/c-api/init.html#c.Py_NoSiteFlag https://docs.python.org/3/library/site.html#site.main

marcelotduarte avatar Apr 29 '20 07:04 marcelotduarte

To read the imported file https://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files

pearlkrishn avatar Jun 15 '20 17:06 pearlkrishn