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

Impossible to build with matplotlib 3.3 on Python 3.7 and 3.8 #5004

Closed
bjonnh opened this issue Jul 17, 2020 · 11 comments · Fixed by #5006
Closed

Impossible to build with matplotlib 3.3 on Python 3.7 and 3.8 #5004

bjonnh opened this issue Jul 17, 2020 · 11 comments · Fixed by #5006

Comments

@bjonnh
Copy link

bjonnh commented Jul 17, 2020

Description of the issue

Trying a simple program main.py

import matplotlib.pyplot as plt

plt.plot([0,1,2], [0,1,1])

Running the application created with pyinstaller --hiddenimport='pkg_resources.py2_warn' main.py

I get:

Traceback (most recent call last):                                                                                                                                                                                                                                                                                             File "main.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 677, in _load_unlocked                                                                                                                                                                                                                                                            File "c:\users\***\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module                                                                                                                                                                              File "site-packages\matplotlib\__init__.py", line 898, in <module>                                                                                                                                                                                                                                                           File "site-packages\matplotlib\cbook\__init__.py", line 480, in _get_data_path                                                                                                                                                                                                                                               File "site-packages\matplotlib\__init__.py", line 239, in wrapper                                                                                                                                                                                                                                                            File "site-packages\matplotlib\__init__.py", line 534, in get_data_path                                                                                                                                                                                                                                                      File "site-packages\matplotlib\__init__.py", line 239, in wrapper                                                                                                                                                                                                                                                            File "site-packages\matplotlib\__init__.py", line 563, in _get_data_path                                                                                                                                                                                                                                                   NameError: name 'defaultParams' is not defined                                                                                                                                                                                                                                                                               [3064] Failed to execute script main

Context information (for bug reports)

  • Output of pyinstaller --version: 3.6 and 4.0-dev0
  • Version of Python: 3.7 and 3.8
  • Platform: Windows (english 10)
  • Did you also try this on another platform? No

What solves it

Reverting to matplotlib 3.2.2 resolve the issue (temporarily).

@rokm
Copy link
Member

rokm commented Jul 18, 2020

Also happens on Fedora 32 with matplotlib 3.3:

(venv) [rok@alpha main]$ ./main 
/home/rok/tmp/mpl/venv/lib64/python3.8/site-packages/PyInstaller/loader/pyimod03_importers.py:493: MatplotlibDeprecationWarning: Matplotlib installs where the data is not in the mpl-data subdirectory of the package are deprecated since 3.2 and support for them will be removed two minor releases later.
  exec(bytecode, module.__dict__)
Traceback (most recent call last):
  File "main.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/home/rok/tmp/mpl/venv/lib64/python3.8/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "matplotlib/__init__.py", line 898, in <module>
  File "matplotlib/cbook/__init__.py", line 480, in _get_data_path
  File "matplotlib/__init__.py", line 239, in wrapper
  File "matplotlib/__init__.py", line 534, in get_data_path
  File "matplotlib/__init__.py", line 239, in wrapper
  File "matplotlib/__init__.py", line 563, in _get_data_path
NameError: name 'defaultParams' is not defined
[16899] Failed to execute script main

As per the initial warning (MatplotlibDeprecationWarning: Matplotlib installs where the data is not in the mpl-data subdirectory of the package are deprecated since 3.2 and support for them will be removed two minor releases later.), matplotlib 3.3.0 requires the mpl-data directory to be in dist/matplotlib/ instead of dist/ itself.

The issue can be temporarily fixed by manually moving the mpl-data directory into matplotlib directory.

@bwoodsend
Copy link
Member

Well for starters: matplotlib.plot doesn't exist. Use the following as a minimal example.

import matplotlib.pyplot as plt

plt.plot([0,1,2], [0,1,1])
plt.show()

But yes, it looks like @rokm is right. It's the data folder and that deprecation warning we've been putting off fixing has finally bit us. In which case the hook needs updating. I'll work on this.

@bjonnh
Copy link
Author

bjonnh commented Jul 18, 2020

Yeah sorry I wrote it from memory but I used pyplot.plt of course.

I ended up being able to make all of it work by reverting to a older matplotlib… I'll keep that for now as it reduces the amount of manual steps for distributing. And I'll update once the new hook is out.

Thanks for taking the time to work on the hook!

bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Jul 19, 2020
This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
paulmueller added a commit to AFM-analysis/PyJibe that referenced this issue Jul 20, 2020
mwoodbri added a commit to ImperialCollegeLondon/strainmap that referenced this issue Jul 30, 2020
dalonsoa added a commit to ImperialCollegeLondon/strainmap that referenced this issue Jul 30, 2020
Legorooj pushed a commit to bwoodsend/pyinstaller that referenced this issue Aug 4, 2020
This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
jussiks added a commit to JYU-IBA/potku that referenced this issue Sep 2, 2020
- For now, mpl is pinned at version 3.2.2 to avoid issues with
  pyinstaller.
  See pyinstaller/pyinstaller#5004
  for more details.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Oct 7, 2020
This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Oct 8, 2020
This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
bwoodsend added a commit to bwoodsend/pyinstaller that referenced this issue Oct 8, 2020
This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
Legorooj pushed a commit that referenced this issue Oct 26, 2020
This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes #5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue #5004) which
presumably isn't intentional.
@venkatMagna
Copy link

for me the solution presented here works
:
https://stackoverflow.com/questions/41870727/pyinstaller-adding-data-files

add the path to the matplotlib and matplotlib-base to the data section in the spec file . This seems to have fixed the issue. for now.Although i still get the deprecation warnings.

@bwoodsend
Copy link
Member

@VenkatKaranam We've fixed this now. You should be able to just:

pip install -U https://github.com/pyinstaller/pyinstaller/archive/develop.zip

Then rebuild using the --clean option.

@venkatMagna
Copy link

venkatMagna commented Nov 2, 2020 via email

@pobs93
Copy link

pobs93 commented May 13, 2021

I have detected an error when you install Pathlib.

If you have Pathlib installed the error reported in this post starts to happen with every version of Matplotlib I have tried
When you uninstall Pathlib, the error stops to happen.

I don´t know how to fix it, but It seems fair to report here

Regards

@bwoodsend
Copy link
Member

pathlib is standard library so you should never need to install it. Unfortunately, there is another pathlib on PyPI which, if installed, gets used instead and consequently breaks anything that wanted to use the original stdlib version. There's another package called enum with exactly the same problem.

orenadav pushed a commit to SeeTrueAI/pyinstaller that referenced this issue Jul 26, 2021
…#5006)

This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
orenadav pushed a commit to SeeTrueAI/pyinstaller that referenced this issue Jul 26, 2021
…#5006)

This alters where matplotlib's ``mpl-data`` folder is put and how it
is found at runtime. This is to support matplotlib>=3.3.0 without
breaking older versions. Fixes pyinstaller#5004.

Previously, the data folder was places in the app's root and a runtime
hook injected the environment variable ``MATPLOTLIBDATA`` to point to
said folder. This variable was deprecated in ``matplotlib 3.1.0`` and
now raises an error in ``matplotlib 3.3.0``.

With this commit, hook-matplotlib.py puts the ``mpl-data`` folder where matplotlib is now
(almost) hard-coded to expect it to be; which is in the parent folder of wherever
``matplotlib.__file__`` points to. With this move, we no longer need a runtime hook.

When I say `almost hard-coded` above, I mean it appears like matplotlib meant to make it
flexible but have mangled it as it now raises a ``NameError`` (see issue pyinstaller#5004) which
presumably isn't intentional.
@maessery
Copy link

@bwoodsend, hi i am relatively new to coding. how would i implement the "--clean option" you mentioned?

@bwoodsend
Copy link
Member

pyinstaller --clean your-code.py but, given how old this is, I seriously doubt that whatever your problem is has anything to do with this.

@hao-y-cpu
Copy link

@VenkatKaranam We've fixed this now. You should be able to just:

pip install -U https://github.com/pyinstaller/pyinstaller/archive/develop.zip

Then rebuild using the --clean option.

Thank you. I have solved the same problem by the way.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants