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

Problem importing Jinja2 in a Windows MSI installation #418

Closed
mar10 opened this issue Sep 1, 2018 · 1 comment
Closed

Problem importing Jinja2 in a Windows MSI installation #418

mar10 opened this issue Sep 1, 2018 · 1 comment

Comments

@mar10
Copy link

mar10 commented Sep 1, 2018

I have a problem importing 'jinja2' in an MSI installation on Windows.

This may be caused by the fact that the package name is 'Jinja2' with a captial 'J',
while it must be imported as 'jinja2'.

While my package runs well as Python installation, this import:

from jinja2 import Environment, FileSystemLoader

fails, when run as exe:

Traceback (most recent call last):
  File "C:\prj\env\wsgidav_build_3.6\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\prj\env\wsgidav_build_3.6\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "wsgidav/server/server_cli.py", line 53, in <module>
  File "C:\Prj\git\wsgidav\wsgidav\default_conf.py", line 17, in <module>
    from wsgidav.addons.dir_browser import WsgiDavDirBrowser
  File "C:\Prj\git\wsgidav\wsgidav\addons\dir_browser\__init__.py", line 32, in <module>
    from jinja2 import Environment, FileSystemLoader
ModuleNotFoundError: No module named 'jinja2'

Interestingly, this import works (capital 'J') inside the exe:

import Jinja2

though it fails shortly afterwards, because the package itself tries to import sub-modules using the small-caps name:

Traceback (most recent call last):
  File "C:\prj\env\wsgidav_build_3.6\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\prj\env\wsgidav_build_3.6\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "wsgidav/server/server_cli.py", line 53, in <module>
  File "C:\Prj\git\wsgidav\wsgidav\default_conf.py", line 17, in <module>
    from wsgidav.addons.dir_browser import WsgiDavDirBrowser
  File "C:\Prj\git\wsgidav\wsgidav\addons\dir_browser\__init__.py", line 22, in <module>
    import Jinja2
  File "C:\prj\env\wsgidav_build_3.6\lib\site-packages\jinja2\__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
ModuleNotFoundError: No module named 'jinja2'

Details

  • I use a virtual environment with Python 3.6.5
  • There I install cx_Freeze-5.1.1-cp36-cp36m-win32.whl
  • also pip install Jinja2, and it gets installed as
    <env>\Lib\site-packages\jinja2\.
  • I run python setup.py bdist_msi from this environment.
  • The resulting package is stored as <project>\build\exe.win32-3.6\lib\Jinja2
  • The import exception can be observed, when running
    <project>\build\exe.win32-3.6\wsgidav.exe

I was able to fix a similar issue with PyYAML (that must be imported as 'yaml')
like so in my setup.py:

install_requires = ["defusedxml", "jsmin", "Jinja2", "PyYAML"]

if use_cx_freeze:
    # cx_Freeze seems to be confused by module name 'PyYAML' which
    # must be imported as 'yaml', so we rename here. However it must
    # be listed as 'PyYAML' in the requirements.txt and be installed!
    install_requires.remove("PyYAML")
    install_requires.append("yaml")

however, this does not work for Jinja, maybe because Windows file names are not
case sensitive:

    install_requires.remove("Jinja2")
    install_requires.append("jinja2")

I would really apreciate any thoughts or hints, that would help to solve or
work-around this problem.

Thank you.

mar10 added a commit to mar10/wsgidav that referenced this issue Sep 1, 2018
mar10 added a commit to mar10/wsgidav that referenced this issue Sep 2, 2018
* SimpleDomainController

* tried to add NT-DC to MSI

* Hotfix for broken Jinja2 import in MSI installer

See marcelotduarte/cx_Freeze#418

* Add pywin32 to MSI installer

* Move dir_browser from addons to own package

* Move some modules around
@mar10
Copy link
Author

mar10 commented Jan 2, 2021

Works for me now with the latest version.

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

No branches or pull requests

1 participant