www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error with matplotlib

reply Samir <samir aol.com> writes:
I am trying to run the code from the "Simple Example" listed in 
the matplotlib-d package page[1] and am running into the 
following error:

$ dub build
Performing "debug" build using 
/usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd for x86_64.
matplotlib-d 0.1.4: building configuration "library"...
Running pre-build commands...
Traceback (most recent call last):
   File 
"/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py",
line 37, in <module>
     gen_pyplot_functions(argv[1])
   File 
"/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py",
line 25, in gen_pyplot_functions
     import matplotlib.pyplot
ImportError: No module named matplotlib.pyplot
Command failed with exit code 1: python 
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py
/home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d

Some information about my environment:
$ uname -a
FreeBSD enterprise 11.2-RELEASE-p9 FreeBSD 11.2-RELEASE-p9 #0: 
Tue Feb  5 15:30:36 UTC 2019     
root amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  
amd64
$ dmd --version
DMD64 D Compiler v2.082.0
Copyright (C) 1999-2018 by The D Language Foundation, All Rights 
Reserved written by Walter Bright
$ python3
Python 3.6.7 (default, Jan 10 2019, 01:15:48)
[GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 
326565)] on freebsd11
Type "help", "copyright", "credits" or "license" for more 
information.
 import matplotlib
 matplotlib.__file__
'/usr/local/lib/python3.6/site-packages/matplotlib/__init__.py'
 matplotlib.__version__
'3.0.2' dub.json: { "name": "matplotlib", "authors": [ "User &" ], "description": "A minimal D application.", "copyright": "Copyright _ 2019, User &", "license": "proprietary", "dependencies": { "matplotlib-d": "~>0.1.4" } } source/app.d: import std.math; import std.range; import std.algorithm; import plt = matplotlibd.pyplot; void main() { auto x = iota(0, 2.05, 0.05).map!(x => x * PI); auto y = x.map!(sin); plt.plot(x, y, "r-", ["label": "$y=sin(x)$"]); plt.xlim(0, 2 * PI); plt.ylim(-1, 1); plt.legend(); plt.savefig("simple.png"); plt.clear(); } [1] http://code.dlang.org/packages/matplotlib-d
Feb 17
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Sunday, 17 February 2019 at 20:19:23 UTC, Samir wrote:
 I am trying to run the code from the "Simple Example" listed in 
 the matplotlib-d package page[1] and am running into the 
 following error:

 [...]
This dub packages enables you to call python coding from D. In this specific case functions from the python module matplotlib.pyplot. The dub package calls this python file which causes your error as python cannot find matplotlib.pyplot. https://github.com/koji-kojiro/matplotlib-d/blob/master/python/prebuild.py Therefore python needs to be installed and also matplotlib.pyplot. I got the dub package example working some weeks ago. In general it should work. Kind regards Andre
Feb 18
parent reply Samir <samir aol.com> writes:
On Monday, 18 February 2019 at 18:27:17 UTC, Andre Pany wrote:
 Therefore python needs to be installed and also 
 matplotlib.pyplot.
Hi Andre, I do have both python3 and matplotlib installed: $ python3 Python 3.6.7 (default, Jan 10 2019, 01:15:48) [GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 326565)] on freebsd11 Type "help", "copyright", "credits" or "license" for more information. >>> matplotlib.__version__ '3.0.2' >>> import matplotlib.pyplot >>> Do I have an issue with the way my dub.json file is configured? This is the first time I am using dub. I also just copied and pasted the code in app.d straight from the matplotlib-d package page (http://code.dlang.org/packages/matplotlib-d). Thanks Samir
Feb 18
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Monday, 18 February 2019 at 19:24:52 UTC, Samir wrote:
 On Monday, 18 February 2019 at 18:27:17 UTC, Andre Pany wrote:
 Therefore python needs to be installed and also 
 matplotlib.pyplot.
Hi Andre, I do have both python3 and matplotlib installed: $ python3 Python 3.6.7 (default, Jan 10 2019, 01:15:48) [GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 326565)] on freebsd11 Type "help", "copyright", "credits" or "license" for more information. >>> matplotlib.__version__ '3.0.2' >>> import matplotlib.pyplot >>> Do I have an issue with the way my dub.json file is configured? This is the first time I am using dub. I also just copied and pasted the code in app.d straight from the matplotlib-d package page (http://code.dlang.org/packages/matplotlib-d). Thanks Samir
The issue is, the dub package is using python 2 (it executes application python) while you have installed matplotlib for Python 3 (application python3). Kind regards Andre
Feb 18
parent reply Samir <samir aol.com> writes:
On Monday, 18 February 2019 at 20:30:23 UTC, Andre Pany wrote:
 The issue is, the dub package is using python 2 (it executes 
 application python) while you have installed matplotlib for 
 Python 3 (application python3).
Thank you for that! After installing the version of matplotlib for python2 and rerunning dub build, I now get the following error: $ dub build Performing "debug" build using /usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd for x86_64. matplotlib-d 0.1.4: building configuration "library"... Running pre-build commands... /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplo .d-mixin-41(191,6): Error: no identifier for declarator void /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,18): Error: found ... when expecting ) /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,21): Error: declaration expected, not ) /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,63): Error: declaration expected, not if /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,89): Error: no identifier for declarator a /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,89): Error: declaration expected, not ) /usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd failed with exit code 1. I don't see a pyplot.d-mixin-41 file in that directory but I do have pyplot.d. Is there an issue with the package itself? Samir
Feb 18
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Monday, 18 February 2019 at 21:28:14 UTC, Samir wrote:
 On Monday, 18 February 2019 at 20:30:23 UTC, Andre Pany wrote:
 [...]
Thank you for that! After installing the version of matplotlib for python2 and rerunning dub build, I now get the following error: $ dub build Performing "debug" build using /usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd for x86_64. matplotlib-d 0.1.4: building configuration "library"... Running pre-build commands... /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplo .d-mixin-41(191,6): Error: no identifier for declarator void /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,18): Error: found ... when expecting ) /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,21): Error: declaration expected, not ) /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,63): Error: declaration expected, not if /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,89): Error: no identifier for declarator a /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotlibd/pyplot d-mixin-41(191,89): Error: declaration expected, not ) /usr/home/samir/dlang/dmd-2.082.0/freebsd/bin64/dmd failed with exit code 1. I don't see a pyplot.d-mixin-41 file in that directory but I do have pyplot.d. Is there an issue with the package itself? Samir
Issue is already solved in master but a new release is missing. Github issue https://github.com/koji-kojiro/matplotlib-d/issues/12 created. In the meantime you could adapt the python script on your local file system in the dub packages cache folder as described here https://github.com/koji-kojiro/matplotlib-d/pull/11/files Kind regards Andre
Feb 18
parent reply Samir <samir aol.com> writes:
On Monday, 18 February 2019 at 21:50:25 UTC, Andre Pany wrote:
 In the meantime you could adapt the python script on your local 
 file system in the dub packages cache folder as described here 
 https://github.com/koji-kojiro/matplotlib-d/pull/11/files
Andre, Thank you very much for your help today! I copied the version of prebuild.py located here[1] and replaced the version located at /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python locally on my machine after which the program ran. I guess I still have the question as to why does the error message refer to issues in /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotli d/pyplot.d-mixin-41 when the solution was changing /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py? Apologies for all of the questions -- I'm just trying to better understand how to incorporate other packages in my simple programs. Samir [1] https://github.com/koji-kojiro/matplotlib-d/blob/master/python/prebuild.py
Feb 18
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Tuesday, 19 February 2019 at 00:05:46 UTC, Samir wrote:
 On Monday, 18 February 2019 at 21:50:25 UTC, Andre Pany wrote:
 In the meantime you could adapt the python script on your 
 local file system in the dub packages cache folder as 
 described here 
 https://github.com/koji-kojiro/matplotlib-d/pull/11/files
Andre, Thank you very much for your help today! I copied the version of prebuild.py located here[1] and replaced the version located at /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python locally on my machine after which the program ran. I guess I still have the question as to why does the error message refer to issues in /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/source/matplotli d/pyplot.d-mixin-41 when the solution was changing /home/samir/.dub/packages/matplotlib-d-0.1.4/matplotlib-d/python/prebuild.py? Apologies for all of the questions -- I'm just trying to better understand how to incorporate other packages in my simple programs. Samir [1] https://github.com/koji-kojiro/matplotlib-d/blob/master/python/prebuild.py
The python script generates a list of available functions in the python package. This list will be used to generate D coding at compilation time. That is the reason, the error occurs in a mixin. Unfortunately one function had the same name as a D keyword (it was the keyword deprecated). The fix was to exclude this function from the list. I think this is the only dub package working this way, as it might be the only package which wrapping python code. Kind regards André
Feb 19
parent Samir <samir aol.com> writes:
On Tuesday, 19 February 2019 at 11:57:00 UTC, Andre Pany wrote:
 The python script generates a list of available functions in 
 the python package.
 This list will be used to generate D coding at compilation time.
 That is the reason, the error occurs in a mixin.
 Unfortunately one function had the same name as a D keyword (it 
 was the keyword deprecated). The fix was to exclude this 
 function from the list.

 I think this is the only dub package working this way, as it 
 might be the only
 package which wrapping python code.
Thanks again for all of your help and explanations, Andre!
Feb 19