Matplotlib crashes when importing pyplot in Blender - python

I know this question has been asked many times before but I cannot find a solution that works for me. I'm running Python 3.5.3 under Blender 2.79 in Windows 10. As I require Blender 2.79, upgrading the Python version is not possible.
I've installed matplotlib and I can import it. However, when I try to import pyplot (e.g. import matplotlib.pyplot as plt), I get a crash to desktop with no error messages of any kind. This happens if I run Python externally or from inside Blender. The weird thing is that I was able to avoid this by changing backends to agg (matplotlib.use('agg')) and this is still working in a previous installation (so I know it's possible to get this to work !), but not in a separate, new installation of Blender. I've tried other backends but they make no difference.
The exact procedure I've tried is as follows :
Downloaded Blender 2.79 from a zip file (I'm using Windows 10) and unpacked it (call this directory /Blender/)
In /Blender/2.79/python/bin I run the command ./python -m ensurepip
In /Blender/2.79/python/scripts I run pip3 install --upgrade pip --user. This gives me pip3 version 20.2.4
In the same directory I run pip3 install --target="/Blender/2.79/python/lib/site-packages" matplotlib --upgrade. The "upgrade" switch is to prevent warnings that the "/bin" directory exists. Doesn't make any difference if I remove it, there's no existing installation of matplotlib. This gives me matplotlib version 3.0.3
Finally I start Python by /Blender/2.79/python/bin/python.exe, and do the above mentioned importmatplotlib.pyplot command which causes the crash.
I've tried this from a completely fresh installation of Blender, which comes with no existing external modules installed. Could there be some conflict with other Python modules elsewhere ? How would I go about diagnosing what's going on ?
Thanks for any ideas !

FIXED ! I remembered I found the solution months ago, but stupidly wrote down the answer in the wrong file...
The problem is that matplotlib is looking for a file that doesn't exist. In c:/users/me/.matplotlib (a hidden file), there's a file ""fontlist-vXXX.json", where XXX is the version number. This is set in line 951 of the file "font_manager.py", located in /python/lib/site-packages/matplotlib. In my case, the font_manager was looking for version 300 but the actual file was 310. Changing the version number in the font_manager.py made everything work correctly.

Related

How to use FEniCS in Spyder with Python 3.8?

I am quite new to python and only did smaller projects so far. For a new project I would like to use FEniCS for solving PDEs. I am working with Windows 10 and already successfully installed Ubuntu (I still do not entirely understand what Ubunutu is needed for). To test solving a PDE I executed a tutorial file "ft01_poisson.py" from the website of the FEniCS project (https://fenicsproject.org/tutorial/) in the Ubuntu command window and it worked.
Afterwards, I also wanted to execute the file in spyder since I will use Spyder for my own project to solve PDEs. I did pip install fenics and when I repeat the command it says Requirement already satisfied: fenics c:\users\airwaves12\anaconda3\envs\spyder-4.1.5\lib\site-packages (2019.1.0).
But when I execute the script in spyder I always get the error ModuleNotFoundError: No module named 'fenics'. In the above-mentioned path there are only folders called fenics_dijitso-2019.1.0.dist-info, fenics_ffc-2019.1.0.post0.dist-info, fenics_fiat-2019.1.0.dist-info, fenics_ufl-2019.1.0.dist-info and fenics-2019.1.0.dist-info.
I know that the "fenics package" consists of different subpackages as "ffc", "FIAT", "ufl" or "dijitso". Those also excist in the above-mentioned file. I tried to manually copy those subpackages saved in folder called "fenics" into the path C:\Users\Airwaves12\anaconda3\envs\spyder-4.1.5\Lib\site-packages but that obviously did not work cause python did not find for example the function UnitSquareMesh().
I spend almost two days reading everything concerning this topic and tried out a lot of things but the most useful advice was from No module named 'dolfin' using Spyder which did not work for me and was originally just for anaconda. How to use FEniCS in Jupyter Notebook or Spyder? did not get an answer for spyder so far.
Does anyone know how to properly use FEniCS with spyder? I would be grateful for any advice.

So i installed numpy . But when i call it in a program an error occurs. Any method to solve it permanently in windows 10

Here is the error
import numpy
Exception has occurred: ModuleNotFoundError
No module named 'numpy'
File "C:\path\to\file\32.py", line 1, in <module>
import numpy
Let me know how did you install the NumPy package; using pip or something else?
If you have multiple python versions, i.e. 2.x and 3.x at the same time, please make sure your interpreter for the 32.py file is the version that you installed NumPy on.
To possibly fix your problem, you should first try installing it and see if there are any errors. You should also check the version of Python you are running on Windows 10, because when you update Python it sometimes switches names between py and python
As you can see, the version of Python has changed between py and python so you should try changing that first.
If this does not work, you should try finding the directory for NumPy and adding it to the system PATH in your script. The installer usually shows you the location by doing the following:
import sys
sys.path.append("<insert numpy location here>")
import NumPy
This should manually force it into finding the package. If none of this works, please tell us and we should be able to find a different solution.
Happy Coding!
If you're using a code editor like PyCharm, you could install it by clicking on
file then settings then the project interpreter setting and install new module! You can search for the module and install.
Make sure that the python version that you want to use is a Windows Environmental Variable. You can test this by running this line in your command line.
> python --version
If you get some other python version that is not the one that you wish to use you can set the python version you want by finding where exactly your Python folder is located and go into settings and set the path as a new variable (I can leave a tutorial for you). If that is too much of a hassle, the Python installers can set the python that you will install as an environmental variable for you. (You could uninstall and reinstall and make sure that you allow it to make it an environmental variable.
After that you should be able to import whatever external packages you want using pip
for example:
pip install numpy

Python PIP Install on Windows missing sub-directories?

My 11-year-old son is trying to follow Carol Vorderman's "Python Games for Kids" book, but is hitting a fundamental problem installing then using Actors module (p.52-onwards of book), on Windows 10. No instructions are provided for installing or importing this. We installed 'actors' (0.5.1b1) using pip:
pip install actors
The install "works" happily, no error is reported, and a (basic) actors installation appears. (We also tried python -m pip install actors, with exactly the same result).
However, any attempt to import actors; e.g.,
from actors import Actor
fails with:
ModuleNotFoundError: no module name 'actors.internal'
of line 29 of actors\__init__.py . Which is fair enough, because it does try to import messages from actors.internal, which does not seem to exist.
Things I checked following the import:
the downloaded .tar.gz file includes a load of subdirectories, including internal; but this doesn't make it into the disc. So it looks like pip isn't handling the .tar.gz file correctly? But it seems hard to believe that such a basic failure has gone undetected.
the disc has 116G free, so it's not running outta space.
I checked other answers (python pip install not working on windows, pip install on a shared directory (windows)), but they do not seem to apply here.
This is a bug in the distribution. It lists packages=['actors'], but it must list all subpackages (internal and utils) too.
The bug was reported in 2016 and still is unresolved. So we can guess the package is abandoned and there is not much you can do to fix it (other than forking and fixing it yourself).
You need to run your program through Pygame Zero, since it adds a few things for you (like opening a window, handling OS events, defining what an Actor or a Sprite are, etc).
Install it with: pip install pgzero
And then instead of running your file normally via python my_file.py
You should run it with: pgzrun my_file.py
If that doesn't work you can try putting import pgzrun on first line of the program and pgzrun.go() on the last line and then running the file normally with: python my_file.py.
Source for the fixes

Test Anaconda build after updating packages

I use conda update --all to update my packages. Recently, I encountered an error with Anaconda build, posted at Error while trying to update and use scipy module in Anaconda. It seems now the issue has been fixed. Is there any way, I can test all modules one by one by importing them and deleting them ? I am requesting this because I have noticed that if import doesn't work, I spend a lot of time figuring out the dependency and then the package that is causing this. For instance, a few minutes ago I found that PyCharm 2018.2.4 breaks with the latest version of matplotlib (3.0.0). Hence, it might be helpful to run some type of test script after running conda update --all to ensure that all packages are indeed working--i.e. importable.
I did some research on this topic and found three sources.
First, Anaconda offers run_test.py (Source: https://conda.io/docs/user-guide/tasks/build-packages/recipe.html). However, being new to the world of Python, I am unsure how to go about running a script in Anaconda terminal.
Second, I found: https://conda.io/docs/user-guide/install/test-installation.html. However, this just tells me the version of the package. I am not interested in the version. I need to know whether all packages import properly.
Finally, I found out that there is a method to run test script for all packages at https://anaconda-installer.readthedocs.io/en/latest/testing.html. However, I am unsure how I can run make in Anaconda terminal. I used to use make long time ago when I worked on gcc on Unix environment. Being new to Python, I am unsure how to go about handling this.
I'd appreciate any thoughts or any test script that could help us verify two things:
a) whether all packages have been installed
b) packages are indeed importable; If the package import fails, the script should terminate with handsome error message highlighting the source (package) where import failed.

python newbie: importing numpy module in eclipse

I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.
So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the
import numpy
import pylab
disappeared so I understood that the reference to that module is ok.
Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).
Can anyone tell what should I do to run this code?
my interpreter setting on eclipse:
If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.
Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *
Edit:
Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.
I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.
I first tried adding a reference to the site-libraries at:
C:\Anaconda3\Lib\site-packages
And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:
C:\Users\myname\AppData\Local\Programs\Python\Python35-32
However, Anacondas installed another version somewhere else. By going into:
Windows > Preferences > PyDev > Interpreters > Python Interpreter
and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.
Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.
Simply removed the old numpy and installed version 6. located here
Another way to circumvent this problem is to use pip install numpy check how to install pip

Categories

Resources