DavHau / mach-nix

Create highly reproducible python environments
MIT License
859 stars 105 forks source link

Cannot get `wand` package to work with Python 3.7 #175

Open sephii opened 3 years ago

sephii commented 3 years ago

I’m getting the following error after setting up a Python shell:

$ ./manage.py 
/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/api.py:169: DeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5
  distname, _, __ = platform.linux_distribution()
Traceback (most recent call last):
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/api.py", line 151, in <module>
    libraries = load_library()
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/api.py", line 140, in load_library
    raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
OSError: cannot find library; tried paths: []

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 19, in <module>
    execute_from_command_line(sys.argv)
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/nix/store/cpzs1hpwzs23c41haa4dap0zjfx6xych-python3-3.7.9/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  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 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/example/utils.py", line 12, in <module>
    from wand.image import Image
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/image.py", line 18, in <module>
    from . import assertions
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/assertions.py", line 155, in <module>
    from .color import Color  # noqa: E402
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/color.py", line 10, in <module>
    from .api import library
  File "/nix/store/3dlbfc202bkznipy2wgcfqb12py4bizg-python3-3.7.9-env/lib/python3.7/site-packages/wand/api.py", line 177, in <module>
    'Try to install:\n  ' + msg)
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  http://docs.wand-py.org/en/latest/guide/install.html

Here’s the shell.nix file:

let
  mach-nix = import (builtins.fetchGit {
    url = "https://github.com/DavHau/mach-nix/";
    ref = "refs/tags/3.0.2";
  }) { python = "python37"; };
in
mach-nix.mkPythonShell {
  requirements = builtins.readFile ./requirements/dev.txt;
}

And the requirements file:

#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile requirements/dev.in
#
aioredis==1.3.1           # via channels-redis
amqp==2.6.1               # via kombu
appdirs==1.4.4            # via virtualenv
asgiref==3.2.10           # via channels, channels-redis, daphne
async-timeout==3.0.1      # via aioredis
attrs==20.1.0             # via automat, service-identity, twisted
autobahn==20.7.1          # via daphne
automat==20.2.0           # via twisted
babel==2.8.0              # via django-phonenumber-field
bcrypt==3.2.0             # via paramiko
billiard==3.6.3.0         # via celery
cairocffi==1.1.0          # via cairosvg, weasyprint
cairosvg==2.4.2           # via weasyprint
celery==4.4.7             # via -r requirements/base.in
certifi==2020.6.20        # via requests, sentry-sdk
cffi==1.14.2              # via bcrypt, cairocffi, cryptography, pynacl, weasyprint
channels-redis==3.0.1     # via -r requirements/base.in
channels==2.4.0           # via -r requirements/base.in, channels-redis
chardet==3.0.4            # via requests
click==7.1.2              # via pip-tools
constantly==15.1.0        # via twisted
cryptography==3.0         # via -r requirements/base.in, autobahn, paramiko, pyopenssl, service-identity
cssselect2==0.3.0         # via cairosvg, weasyprint
daphne==2.5.0             # via -r requirements/base.in, channels
defusedxml==0.6.0         # via cairosvg, odfpy, python3-openid
diff-match-patch==20200713  # via django-import-export
distlib==0.3.1            # via virtualenv
dj-database-url==0.5.0    # via -r requirements/base.in
django-admin-sortable==2.2.3  # via -r requirements/base.in
django-allauth==0.42.0    # via -r requirements/base.in
django-ckeditor==5.9.0    # via -r requirements/base.in
django-countries==6.1.3   # via -r requirements/base.in
django-debug-toolbar==2.2  # via -r requirements/dev.in
django-extensions==3.0.5  # via -r requirements/dev.in
django-formtools==2.2     # via django-two-factor-auth
django-import-export==2.3.0  # via -r requirements/base.in
django-js-asset==1.2.2    # via django-ckeditor
django-modeltranslation==0.15.1  # via -r requirements/base.in
django-otp==0.9.4         # via django-two-factor-auth
django-phonenumber-field==3.0.1  # via django-two-factor-auth
django-polymorphic==3.0.0  # via -r requirements/base.in
django-two-factor-auth==1.11.0  # via -r requirements/base.in
django==2.2.15            # via -r requirements/base.in, channels, django-admin-sortable, django-allauth, django-debug-toolbar, django-formtools, django-import-export, django-modeltranslation, django-otp, django-phonenumber-field, django-polymorphic, django-two-factor-auth, djangorestframework, easy-thumbnails
djangorestframework-jwt==1.11.0  # via -r requirements/base.in
djangorestframework==3.11.1  # via -r requirements/base.in
easy-thumbnails==2.7      # via -r requirements/base.in
et-xmlfile==1.0.1         # via openpyxl
fabric3==1.14.post1       # via -r requirements/dev.in
faker==4.1.2              # via -r requirements/base.in
filelock==3.0.12          # via tox, virtualenv
gitric==0.4               # via -r requirements/dev.in
hiredis==1.1.0            # via aioredis
html5lib==1.1             # via weasyprint
hyperlink==20.0.1         # via twisted
idna==2.10                # via hyperlink, requests, twisted
importlib-metadata==1.7.0  # via kombu, pluggy, tox, virtualenv
incremental==17.5.0       # via twisted
jdcal==1.4.1              # via openpyxl
kombu==4.6.11             # via celery
markuppy==1.14            # via tablib
msgpack==1.0.0            # via channels-redis
oauthlib==3.1.0           # via requests-oauthlib
odfpy==1.4.1              # via tablib
openpyxl==3.0.5           # via tablib
packaging==20.4           # via tox
paramiko==2.7.1           # via fabric3
phonenumbers==8.12.8      # via -r requirements/base.in
pillow==7.2.0             # via cairosvg, easy-thumbnails
pip-tools==5.3.1          # via -r requirements/dev.in
pluggy==0.13.1            # via tox
psycopg2-binary==2.8.5    # via -r requirements/base.in
py==1.9.0                 # via tox
pyasn1-modules==0.2.8     # via service-identity
pyasn1==0.4.8             # via pyasn1-modules, service-identity
pycparser==2.20           # via cffi
pyhamcrest==2.0.2         # via twisted
pyjwt==1.7.1              # via djangorestframework-jwt, twilio
pynacl==1.4.0             # via paramiko
pyopenssl==19.1.0         # via twisted
pyparsing==2.4.7          # via packaging
pypdf2==1.26.0            # via -r requirements/base.in
pyphen==0.9.5             # via weasyprint
python-dateutil==2.8.1    # via faker
python-memcached==1.59    # via -r requirements/base.in
python3-openid==3.2.0     # via django-allauth
pytz==2020.1              # via babel, celery, django, twilio
pyyaml==5.3.1             # via -r requirements/base.in, tablib
qrcode==6.1               # via django-two-factor-auth
redis==3.5.3              # via -r requirements/base.in
requests-oauthlib==1.3.0  # via django-allauth
requests==2.24.0          # via django-allauth, requests-oauthlib, twilio
sentry-sdk==0.17.0        # via -r requirements/base.in
service-identity==18.1.0  # via twisted
six==1.15.0               # via automat, bcrypt, cryptography, django-modeltranslation, fabric3, html5lib, packaging, pip-tools, pynacl, pyopenssl, python-dateutil, python-memcached, qrcode, tox, twilio, virtualenv
sqlparse==0.3.1           # via django, django-debug-toolbar
tablib[html,ods,xls,xlsx,yaml]==2.0.0  # via django-import-export
text-unidecode==1.3       # via faker
tinycss2==1.0.2           # via cairosvg, cssselect2, weasyprint
toml==0.10.1              # via tox
tox==3.19.0               # via -r requirements/dev.in
twilio==6.45.0            # via -r requirements/base.in
twisted[tls]==20.3.0      # via daphne
txaio==20.4.1             # via autobahn
urllib3==1.25.10          # via requests, sentry-sdk
vine==1.3.0               # via amqp, celery
virtualenv==20.0.31       # via tox
wand==0.6.2               # via -r requirements/base.in
weasyprint==51            # via -r requirements/base.in
webencodings==0.5.1       # via cssselect2, html5lib, tinycss2
werkzeug==1.0.1           # via -r requirements/dev.in
xlrd==1.2.0               # via tablib
xlwt==1.3.0               # via tablib
zipp==3.1.0               # via importlib-metadata
zope.interface==5.1.0     # via twisted

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools

I tried adding providers = {"wand" = "nixpkgs";}; but I got another error ("requirements conflict").

DavHau commented 3 years ago

There is a magickwand library available from pypi, but this doesn't seem to fix the problem. I also tried including imagemagick via packagesExtra, but also no success. Will investigate more, when I find some time.

DavHau commented 3 years ago

Wand seems to require specific environment variables set in order to be able to load its dependencies. Wand is already packaged in nixpkgs and there this is fixed via patch. (see nix edit nixpkgs/nixos-20.09#python3Packages.Wand).

You can just use the sdist provider for this package. It will take the existing nix expression and replace the source with the required version:

mach-nix.mkPython {
  requirements = builtins.readFile ./requirements/dev.txt;
  providers.wand = "sdist";
}