Nuitka Convert Error With Weasyprint in Python Code

Created on 24 Sep 2019  路  8Comments  路  Source: Nuitka/Nuitka

I am trying to compile executable file from Python code which uses WeasyPrint for PDF conversion using Nuitka but giving error.

I have installed MinGW64 for C compiler under "c:MinGW64".

python -m nuitka --follow-imports --standalone --mingw64 websense-url-checker.py

After running the code it gives the following warning.

Nuitka:WARNING:Use '--plugin-enable=pylint-warnings' for: Understand PyLint/PyDev annotations for warnings.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\PIL\Image.py:432' may require use of '--incl
ude-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\cffi\verifier.py:151' may require use of '--
include-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\cx_Freeze\hooks.py:468' may require use of '
--include-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\defusedxml\common.py:83' may require use of
'--include-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\jinja2\loaders.py:472' may require use of '-
-include-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\jinja2\utils.py:142' may require use of '--i
nclude-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\jinja2\utils.py:143' may require use of '--i
nclude-plugin-directory' or '--include-plugin-files'.

Nuitka:WARNING:Unresolved '__import__' call at 'C:\Users\[USER-NAME]\DOCUME~1\TEST-
P~1\WEBSEN~1\venv\lib\site-packages\requests\packages.py:7' may require use of '
--include-plugin-directory' or '--include-plugin-files'.

It generates executable though but running the exe it gives the following.

websense-url-checker.dist\websense-url-checker.exe

Traceback (most recent call last):
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\websense-url-checker.py", line 3, in <module>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\weasyprint\__init__.py", line 20, in <module weasyprint>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\cssselect2\__init__.py", line 20, in <module cssselect2>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\cssselect2\compiler.py", line 7, in <module cssselect2.compiler>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\tinycss2\__init__.py", line 10, in <module tinycss2>
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\pathlib.py", line 1206, in read_text
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\pathlib.py", line 1193, in open
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\pathlib.py", line 1046, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\[USER-NAME]\\Documents\\test-python\\websense-url-checker\\websense-url-checker.dist\\tinycss2\\VERSION'
bug

Most helpful comment

Sorry for the tardiness of my reaction - just recovered from severe internet outages.
Can you please provide an as small as possible snippet to reproduce this?
Ideally just the imports or similar.
Looks like the standard situation of adjusting some implicit imports and missing data files ...

All 8 comments

Also tried with the following command.

python -m nuitka --follow-imports --show-progress --show-scons --show-modules --include-package=pyphen --include-package=tinycss2 --include-package=cairocffi --include-package=weasyprint --standalone websense-url-checker.py

But getting the following error

websense-url-checker.dist\websense-url-checker.exe

Traceback (most recent call last):
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\websense-url-checker.py", line 3, in <module>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\weasyprint\__init__.py", line 20, in <module weasyprint>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\webs
ense-url-checker.dist\cssselect2\__init__.py", line 20, in <module cssselect2>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\webs
ense-url-checker.dist\cssselect2\compiler.py", line 7, in <module cssselect2.com
piler>
  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\[USER-NAME]\Documents\test-python\websense-url-checker\webs
ense-url-checker.dist\tinycss2\__init__.py", line 10, in <module tinycss2>
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\webs
ense-url-checker.dist\pathlib.py", line 1206, in read_text
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\webs
ense-url-checker.dist\pathlib.py", line 1193, in open
  File "C:\Users\[USER-NAME]\Documents\test-python\websense-url-checker\webs
ense-url-checker.dist\pathlib.py", line 1046, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\[USER-NAME]\\Documents\\test-python\\websense-url-checker\\websense-url-checker.dist\\tinycss2\\VERSION'

Sorry for the tardiness of my reaction - just recovered from severe internet outages.
Can you please provide an as small as possible snippet to reproduce this?
Ideally just the imports or similar.
Looks like the standard situation of adjusting some implicit imports and missing data files ...

I have looked in both your pivotal imports, tinycss2 and weasyprint. Both rely on a same-named file VERSION (no extension). These must be prersent obviously, but will not be copied without special precautions.
Even if that is once taken care of, obviously only one such file can exist in the dist folder. So you will see a wrong version for one of the packages ...

Sorry for the tardiness of my reaction - just recovered from severe internet outages.
Can you please provide an as small as possible snippet to reproduce this?
Ideally just the imports or similar.
Looks like the standard situation of adjusting some implicit imports and missing data files ...

Following are the imports of python3 packages in my application

import requests
import csv
from weasyprint import HTML
from jinja2 import Environment, FileSystemLoader
from datetime import datetime
import smtplib
import configparser
from string import Template
import logging

from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

If you need any other reference please feel free to ask.

Thank you.

Again having massive internet connection issues, therefore this post via e-mail in the hope it will get transmitted asynchronously.
But I was able to upload Nuitka plugin changes for this issue:
The jorj branch has an updated DataFileCollector.py plugin, which is sufficient to successfully to execute your imports.
Good look with it!

Jorj

I have used the jorj branch but getting the following error after generating the exe.

websense-url-checker.exe

Traceback (most recent call last):
  File "C:\Users\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\websense-url-checker.py", line 3, in <module>
  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\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\weasyprint\__init__.py", line 20, in <module weasyprint>
  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\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\cssselect2\__init__.py", line 20, in <module cssselect2>
  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\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\cssselect2\compiler.py", line 7, in <module cssselect2.compiler>
  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\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\tinycss2\__init__.py", line 10, in <module tinycss2>
  File "C:\Users\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\pathlib.py", line 1206, in read_text
  File "C:\Users\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\pathlib.py", line 1193, in open
  File "C:\Users\[USERNAME]\Documents\test-python\websense-url-checker\websense-url-checker.dist\pathlib.py", line 1046, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\[USERNAME]\\Documents\\test-python\\websense-url-checker\\websense-url-checker.dist\\tinycss2\\VERSION'

Can you please confirm that your DataFileCollectorPlugin.py located in nuitka/plugins/standard looks like so:

grafik

I have downloaded the source code and used

python setup.py install

but after installing when running

nuitka --version

it is showing

0.6.5
Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
Executable: C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python37\python.exe
OS: Windows
Arch: x86_64

Please help me to figure out what I doing wrong.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickrh75 picture nickrh75  路  3Comments

anki-code picture anki-code  路  5Comments

maaaaz picture maaaaz  路  7Comments

jamesstidard picture jamesstidard  路  12Comments

dzg picture dzg  路  10Comments