Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.22k stars 686 forks source link

No module named 'weasyprint' #988

Closed dasharath1996 closed 5 years ago

dasharath1996 commented 5 years ago

Traceback (most recent call last): File "C:\Users\SAJAN\AppData\Local\Programs\Python\Python38-32\resume-maker-master\app\make.py", line 1, in from weasyprint import HTML ModuleNotFoundError: No module named 'weasyprint'

please lookup this why this getting module not found but, i have already install weasyprint

Tontyna commented 5 years ago

This error indicates that there is no weasyprint folder in Python's sys.path list. Which would be very strange when you installed it via pip as described in the docs. At least unless you start Python in a special, limited, configured environment or in isolated mode...

How did you install WeasyPrint / what's the output of pip show weasyprint? How do you start your failing script? The full traceback and the output of print(*sys.path, sep='\n') might help me to help you.

dasharath1996 commented 5 years ago
C:\Users\SAJAN\PycharmProjects\resume-maker-master>pip install weasyprint
Collecting weasyprint
  Using cached https://files.pythonhosted.org/packages/ca/1a/1925cf1e39e5526d9c686a31f798523e06ea45f20c958a429317a1110ee4/WeasyPrint-50-py3-none-any.whl
Collecting CairoSVG>=2.4.0
  Using cached https://files.pythonhosted.org/packages/8e/3a/762f9272c20db092f4d537aaf364dd0770ecf8f7101b58c4e933e99ee2f6/CairoSVG-2.4.2-py3-none-any.whl
Collecting html5lib>=0.999999999
  Using cached https://files.pythonhosted.org/packages/a5/62/bbd2be0e7943ec8504b517e62bab011b4946e1258842bc159e5dfde15b96/html5lib-1.0.1-py2.py3-none-any.whl
Collecting cssselect2>=0.1
  Using cached https://files.pythonhosted.org/packages/c4/a1/1a37602bbcfa2f7c079758f31555776a00a947e43457a3e0110b2165c7d9/cssselect2-0.2.2-py2.py3-none-any.whl
Collecting tinycss2>=1.0.0
  Using cached https://files.pythonhosted.org/packages/94/2c/4e501f9c351343c8ba10d70b5a7ca97cdab2690af043a6e52ada65b85b6b/tinycss2-1.0.2-py3-none-any.whl
Requirement already satisfied: setuptools>=39.2.0 in c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages (from weasyprint) (41.6.0)
Collecting Pyphen>=0.8
  Using cached https://files.pythonhosted.org/packages/15/82/08a3629dce8d1f3d91db843bb36d4d7db6b6269d5067259613a0d5c8a9db/Pyphen-0.9.5-py2.py3-none-any.whl
Collecting cffi>=0.6
  Using cached https://files.pythonhosted.org/packages/f8/26/5da5cafef77586e4f7a136b8a24bc81fd2cf1ecb71b6ec3998ffe78ea2cf/cffi-1.13.2-cp38-cp38-win32.whl
Collecting cairocffi>=0.9.0
  Using cached https://files.pythonhosted.org/packages/f7/99/b3a2c6393563ccbe081ffcceb359ec27a6227792c5169604c1bd8128031a/cairocffi-1.1.0.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\sajan\appdata\local\programs\python\python38-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\SAJAN\\AppData\\Local\\Temp\\pip-inst
all-vjwgm1ql\\cairocffi\\setup.py'"'"'; __file__='"'"'C:\\Users\\SAJAN\\AppData\\Local\\Temp\\pip-install-vjwgm1ql\\cairocffi\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file
__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\SAJAN\AppData\Local\Temp\pip-install-vjwgm1ql\
cairocffi\pip-egg-info'
         cwd: C:\Users\SAJAN\AppData\Local\Temp\pip-install-vjwgm1ql\cairocffi\
    Complete output (100 lines):
    Traceback (most recent call last):
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 154, in save_modules
        yield saved
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 195, in setup_context
        yield
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 250, in run_setup
        _execfile(setup_script, ns)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 45, in _execfile
        exec(code, globals, locals)
      File "C:\Users\SAJAN\AppData\Local\Temp\easy_install-fyhblda5\cffi-1.13.2\setup.py", line 127, in <module>
      File "C:\Users\SAJAN\AppData\Local\Temp\easy_install-fyhblda5\cffi-1.13.2\setup.py", line 105, in uses_msvc
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\command\config.py", line 225, in try_compile
        self._compile(body, headers, include_dirs, lang)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\command\config.py", line 132, in _compile
        self.compiler.compile([src], include_dirs=include_dirs)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\_msvccompiler.py", line 360, in compile
        self.initialize()
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\_msvccompiler.py", line 253, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 171, in msvc14_get_vc_env
        return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 1075, in __init__
        self.si = SystemInfo(self.ri, vc_ver)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 547, in __init__
        vc_ver or self._find_latest_available_vs_ver())
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 561, in _find_latest_available_vs_ver
        raise distutils.errors.DistutilsPlatformError(
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\SAJAN\AppData\Local\Temp\pip-install-vjwgm1ql\cairocffi\setup.py", line 10, in <module>
        setup(
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\__init__.py", line 144, in setup
        _install_setup_requires(attrs)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\__init__.py", line 139, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\dist.py", line 717, in fetch_build_eggs
        resolved_dists = pkg_resources.working_set.resolve(
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\pkg_resources\__init__.py", line 780, in resolve
        dist = best[req.key] = env.best_match(
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\pkg_resources\__init__.py", line 1065, in best_match
        return self.obtain(req, installer)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\pkg_resources\__init__.py", line 1077, in obtain
        return installer(requirement)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\dist.py", line 787, in fetch_build_egg
        return cmd.easy_install(req)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\easy_install.py", line 679, in easy_install
        return self.install_item(spec, dist.location, tmpdir, deps)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\easy_install.py", line 705, in install_item
        dists = self.install_eggs(spec, download, tmpdir)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\easy_install.py", line 890, in install_eggs
        return self.build_and_install(setup_script, setup_base)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\easy_install.py", line 1158, in build_and_install
        self.run_setup(setup_script, setup_base, args)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\easy_install.py", line 1144, in run_setup
        run_setup(setup_script, args)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 253, in run_setup
        raise
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\contextlib.py", line 131, in __exit__
        self.gen.throw(type, value, traceback)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 195, in setup_context
        yield
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\contextlib.py", line 131, in __exit__
        self.gen.throw(type, value, traceback)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 166, in save_modules
        saved_exc.resume()
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 141, in resume
        six.reraise(type, exc, self._tb)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\_vendor\six.py", line 685, in reraise
        raise value.with_traceback(tb)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 154, in save_modules
        yield saved
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 195, in setup_context
        yield
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 250, in run_setup
        _execfile(setup_script, ns)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\sandbox.py", line 45, in _execfile
        exec(code, globals, locals)
      File "C:\Users\SAJAN\AppData\Local\Temp\easy_install-fyhblda5\cffi-1.13.2\setup.py", line 127, in <module>
      File "C:\Users\SAJAN\AppData\Local\Temp\easy_install-fyhblda5\cffi-1.13.2\setup.py", line 105, in uses_msvc
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\command\config.py", line 225, in try_compile
        self._compile(body, headers, include_dirs, lang)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\command\config.py", line 132, in _compile
        self.compiler.compile([src], include_dirs=include_dirs)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\_msvccompiler.py", line 360, in compile
        self.initialize()
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\distutils\_msvccompiler.py", line 253, in initialize
        vc_env = _get_vc_env(plat_spec)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 171, in msvc14_get_vc_env
        return EnvironmentInfo(plat_spec, vc_min_ver=14.0).return_env()
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 1075, in __init__
        self.si = SystemInfo(self.ri, vc_ver)
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 547, in __init__
        vc_ver or self._find_latest_available_vs_ver())
      File "c:\users\sajan\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\msvc.py", line 561, in _find_latest_available_vs_ver
        raise distutils.errors.DistutilsPlatformError(
    distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

pip show weasyprint? o/p WARNING: Package(s) not found: weasyprint print(*sys.path, sep='\n')? o/p Unable to initialize device PRN

Tontyna commented 5 years ago

pip install failed so there is of course no WeasyPrint.

Main reason being this one:

distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/

More infos here: https://wiki.python.org/moin/WindowsCompilers

BTW: The print(*sys.path, sep='\n') wasn't meant to be run in the Windows console, it's a Python command.

dasharath1996 commented 5 years ago

could you tell me, how can i install weasyprint i have already try with visual studio also but still it same error is occurs which is mention above

liZe commented 5 years ago

could you tell me, how can i install weasyprint i have already try with visual studio also but still it same error is occurs which is mention above

Pip doesn't find the C++ build tools for Visual Studio, you have to install them.

The URL is given in the error message: https://visualstudio.microsoft.com/downloads/. There's a "Build tools" section a the bottom of the page, and at the bottom of this section there's a link to download them.

You can then launch pip install weasyprint again.

Tontyna commented 5 years ago

@liZe any chance to deploy cairocffi as wheel? The answer is probably "no" because cairocffi needs to be linked to cairo at install time...

Wondering why I didn't mention the C++ build tools when I rewrote the installation instructions for WeasyPrint on Windows -- most likely I simply forgot about it due to the predominant GTK stuff.

Tontyna commented 5 years ago

Wondering why I didn't mention the C++ build tools

That's why: https://github.com/Kozea/WeasyPrint/pull/668#issuecomment-413791202 But obviously this isn't true. The compiler must have been there, installed by some other application I wasn't aware of.

liZe commented 5 years ago

But obviously this isn't true. The compiler must have been there, installed by some other application I wasn't aware of

CairoCFFI used to be distributed as a wheel, but it's not anymore because the binding file is done at install time and may (does? not really does?) change depending on the target computer.

We could try to compare the generated files and see if there's a solution to generate them once and include them in a wheel … and of course check that it works everywhere.

Tontyna commented 5 years ago

We could complement the WeasyPrint installation instruction with sth like "if pip install fails then have a look at the installation docs of the failing required module" :smirk:

GaikwadDS commented 4 years ago

Hello, I followed every step mentioned in the document https://weasyprint.readthedocs.io/en/latest/install.html#step-2-update-pip-and-setuptools-packages. I have set the env variable path also to C:\msys32\mingw32\bin (It's for 32 bit). When I run python -m weasyprint http://weasyprint.org weasyprint.pdf, I get C:\msys32\mingw32\bin\python.exe: No module named weasyprint. pip show weasyprint shows the following, Name: WeasyPrint Version: 51 Summary: The Awesome Document Factory Home-page: https://weasyprint.org/ Author: Simon Sapin Author-email: community@kozea.fr License: BSD Location: c:\users\darshan gaikwad\.virtualenvs\kerykeion-lgzdcstv\lib\site-packages Requires: Pyphen, setuptools, CairoSVG, cairocffi, html5lib, cssselect2, cffi, tinycss2 Required-by: Can you please help me? .. Unable to understand what's my mistake.

Tontyna commented 4 years ago

@GaikwadDS cf #1151

Looks like you installed mingw32's Python package: There is a Python executable in C:\msys32\mingw32\bin\python.exe.

When you run python -m weasyprint Windows looks for the first Python executable in your PATH. Since you put the mingw32 folder at the beginning of your PATH ... the wrong executable (i.e. a Python without WeasyPrint) is found.

Since your pip command succeeds in finding python-with-weasyprint, the command where pip should tell you where the required python.exe is located. Besides that: There should be an activate.bat or similar in your virtualenv which pushes the correct python in front of everything.

Unless the mingw32 Python package is required for something else, I suggest to uninstall it.

ArwaG commented 3 years ago

@Tontyna

Hello, I have a similar problem. When I try to run python -m weasyprint it results with C:\msys64\mingw64\bin\python.exe: No module named weasyprint .

I did the suggested solution:

Unless the mingw32 Python package is required for something else, I suggest to uninstall it.

but I just removed it from the C:\msys64\mingw64\bin file I did not really uninstall it, just to check if this will work for me. It did not work for me and I was back to this error:

OSError: no library called "cairo" was found cannot load library 'C:\msys64\mingw64\bin\libcairo-2.dll': error 0x7f cannot load library 'libcairo.so.2': error 0x7e cannot load library 'libcairo.2.dylib': error 0x7e cannot load library 'libcairo-2.dll': error 0x7f

So I returned the python.exe file to C:\msys64\mingw64\bin folder.

Other information regarding my issue that might clarify it:

C:\Users\Arwa\anaconda3\Scripts\pip.exe C:\Users\Arwa\AppData\Local\Programs\Python\Python37\Scripts\pip.exe C:\Users\Arwa\anaconda3\Scripts\weasyprint.exe

the procedure entry point inflateReset2 could not be located in the dynamic link library C:\msys64\bin\libpng16-16.dll.

C:\Users\Arwa\anaconda3\Scripts\pip.exe C:\Users\Arwa\AppData\Local\Programs\Python\Python37\Scripts\pip.exe C:\msys64\mingw64\bin\python.exe C:\Users\Arwa\anaconda3\python.exe C:\Users\Arwa\AppData\Local\Programs\Python\Python37\python.exe C:\Users\Arwa\AppData\Local\Microsoft\WindowsApps\python.exe

I hope this makes sense.

liZe commented 3 years ago

@Arwa720 Your versions of Python installed by Anaconda and MSYS2 are obviously mixed: pip is from Anaconda and python from MSYS2.

What you can do as a workaround is:

The real fix is to understand why you have Anaconda and MSYS2 installed and keep only one to launch Python apps if possible. By the way, WeasyPrint will be available on Anaconda for Windows soon (see conda-forge/weasyprint-feedstock#18), that may be useful for you :wink:.

Tontyna commented 3 years ago

Install MSYS2 and check that the default Python is from MSYS2

I don't recommend this -- MSYS2 Python is special. It's working well from within the MSYS shell, but unexpected things happen if you treat it like a regular Windows Python.

I'd recommend staying with the Anaconda Python. @Arwa720 already successfully installed the WeasyPrint module: After removing the MSYS Python the error wasn't about not finding weasyprint, but the famous cannot load cairo. Which should be fixed by inserting the path to the desired GTK3-Runtime (no matter whether it's from MSYS or from the installer) at the beginning of the PATH.

ArwaG commented 3 years ago

@Tontyna Yes I did insert a path. But thank you the problem was solved when I just deleted the python.exe from MYSYS2 folder and just waited for about an hour. I don't know how but this just worked after waiting.

Tontyna commented 3 years ago

@Arwa720 You probably closed and restarted your command prompt/shell/environment -- without restart they usually don't notice changed Windows environment variables.

ArwaG commented 3 years ago

@Tontyna Maybe but I don't think so, because I restarted the pc as one of the solutions but it did not work as well previously

leviouwendijk commented 4 weeks ago

I ran into this issue as well, more on that here.