Kernel restart when using simple matplotlib [duplicate] - python

I have create this simple env with conda:
conda create -n test python=3.8.5 pandas scipy numpy matplotlib seaborn jupyterlab
The following code in jupyter lab crashes the kernel :
import matplotlib.pyplot as plt
plt.subplot()
I don't face the problem on Linux. The problem is when I try on Windows 10.
There are no errors on the jupyter lab console (where I started the server), and I have no idea where to investigate.

Update 2021-11-06
The default pkgs/main channel for conda has reverted to using freetype 2.10.4 for Windows, per main / packages / freetype.
If you are still experiencing the issue, use conda list freetype to check the version: freetype != 2.11.0
If it is 2.11.0, then change the version, per the solution, or conda update --all (providing your default channel isn't changed in the .condarc config file).
Solution
If this is occurring after installing Anaconda, updating conda or freetype since Oct 27, 2021.
Go to the Anaconda prompt and downgrade freetype 2.11.0 in any affected environment.
conda install freetype=2.10.4
Relevant to any package using matplotlib and any IDE
For example, pandas.DataFrame.plot and seaborn
Jupyter, Spyder, VSCode, PyCharm, command line.
Discovery
An issue occurs after updating with the most current updates from conda, released Friday, Oct 29.
After updating with conda update --all, there's an issue with anything related to matplotlib in any IDE (not just Jupyter).
I tested this in JupyterLab, PyCharm, and python from the command prompt.
PyCharm: Process finished with exit code -1073741819
JupyterLab: kernel just restarts and there are no associated errors or Traceback
command prompt: a blank interactive matplotlib window will appear briefly, and then a new command line appears.
The issue seems to be with conda update --all in (base), then any plot API that uses matplotlib (e.g. seaborn and pandas.DataFrame.plot) kills the kernel in any environment.
I had to reinstall Anaconda, but do not do an update of (base), then my other environments worked.
I have not figured out what specifically is causing the issue.
I tested the issue with python 3.8.12 and python 3.9.7
Current Testing:
Following is the conda revision log.
Prior to conda update --all this environment was working, but after the updates, plotting with matplotlib crashes the python kernel
2021-10-31 10:47:22 (rev 3)
bokeh {2.3.3 (defaults/win-64) -> 2.4.1 (defaults/win-64)}
click {8.0.1 (defaults/noarch) -> 8.0.3 (defaults/noarch)}
filelock {3.0.12 (defaults/noarch) -> 3.3.1 (defaults/noarch)}
freetype {2.10.4 (defaults/win-64) -> 2.11.0 (defaults/win-64)}
imagecodecs {2021.6.8 (defaults/win-64) -> 2021.8.26 (defaults/win-64)}
joblib {1.0.1 (defaults/noarch) -> 1.1.0 (defaults/noarch)}
lerc {2.2.1 (defaults/win-64) -> 3.0 (defaults/win-64)}
more-itertools {8.8.0 (defaults/noarch) -> 8.10.0 (defaults/noarch)}
pyopenssl {20.0.1 (defaults/noarch) -> 21.0.0 (defaults/noarch)}
scikit-learn {0.24.2 (defaults/win-64) -> 1.0.1 (defaults/win-64)}
statsmodels {0.12.2 (defaults/win-64) -> 0.13.0 (defaults/win-64)}
sympy {1.8 (defaults/win-64) -> 1.9 (defaults/win-64)}
tqdm {4.62.2 (defaults/noarch) -> 4.62.3 (defaults/noarch)}
xlwings {0.24.7 (defaults/win-64) -> 0.24.9 (defaults/win-64)}
The issue seems to be freetype
Downgrading from 2.11.0 to 2.10.4 resolved the issue and made the environment work with matplotlib
Went to post a bug report and discovered there is [Bug]: Matplotlib crashes Python #21511

For anybody that downgrading to freetype=2.10.4 didn't work. In my case the issue happened after installing the new version of scikit-learn=1.11 from conda-forge channel. After trying out many options the following worked for me:
reinstall numpy from main/pkg to conda-forge channel
reinstall mkl package conda -c intel mkl
reinstall matplotlib=4.3 from conda-forge
It's quite a drastic measure, since you have to reinstall all dependecies that rely on NumPy (Pandas, TensorFlow etc.), but it was the only one that worked for me.

I had the same issue and after a fair amount of investigation and troubleshooting, the fix was pretty straight forward:
conda update -c anaconda numpy
conda upgrade -c conda-forge matplotlib
After that it ran fine and my visuals plotted without issue.

Related

Why am I unable to import the pcse (python crop simulation environment) into my jupyter notebook and how do I fix it?

I installed pcse using this user guide: https://pcse.readthedocs.io/en/stable/user_guide.html#getting-started . I am unable to import the package in jupyter notebook while I have the environment activated in the miniconda terminal.
(base) C:\Users\merej>activate py3_pcse
(py3_pcse) C:\Users\merej>
I don't know if I'm required to add the virtual environment to jupyter notebook in order to use it so I added it using
pip install --user ipykernel
python -m ipykernel install --user --name=py3_pcse
The Kernel shows up in Jupyter notebook;However, Jupyter notebook is unable to connect to the notebook server. This is not a problem when I create a python3 notebook.
I saw that this may be a problem with Tornado so I uninstalled my current tornado, installed tornado 5.1.1, got an error message saying the tornando 5.1.1 would not work with my current version of jupyter notebook, uninstalled tornado 5.1.1, and reinstalled the updated version of tornado.
(py3_pcse) C:\Users\merej>pip uninstall tornado
Found existing installation: tornado 6.2
Uninstalling tornado-6.2:
Would remove:
c:\users\merej\miniconda3\envs\py3_pcse\lib\site-packages\tornado-6.2.dist-info\*
c:\users\merej\miniconda3\envs\py3_pcse\lib\site-packages\tornado\*
Proceed (Y/n)? y
Successfully uninstalled tornado-6.2
(py3_pcse) C:\Users\merej>pip install tornado==5.1.1
Collecting tornado==5.1.1
Downloading tornado-5.1.1.tar.gz (516 kB)
---------------------------------------- 516.8/516.8 kB 550.0 kB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Building wheels for collected packages: tornado
Building wheel for tornado (setup.py) ... done
Created wheel for tornado: filename=tornado-5.1.1-cp38-cp38-win_amd64.whl size=449834 sha256=160b8413fde8328df013e8729e86a92138e32c365dc6d9dc97a3e04b6cca17ea
Stored in directory: c:\users\merej\appdata\local\pip\cache\wheels\25\a1\e3\b0d37c6c451fc21f290cf026f6352382e6cbced32dc3f6a37a
Successfully built tornado
Installing collected packages: tornado
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
notebook 6.4.12 requires tornado>=6.1, but you have tornado 5.1.1 which is incompatible.
jupyterlab 3.4.4 requires tornado>=6.1.0, but you have tornado 5.1.1 which is incompatible.
jupyter-server 1.18.1 requires tornado>=6.1.0, but you have tornado 5.1.1 which is incompatible.
jupyter-client 7.3.5 requires tornado>=6.2, but you have tornado 5.1.1 which is incompatible.
ipykernel 6.15.2 requires tornado>=6.1, but you have tornado 5.1.1 which is incompatible.
Successfully installed tornado-5.1.1
(py3_pcse) C:\Users\merej>pip uninstall tornado
Found existing installation: tornado 5.1.1
Uninstalling tornado-5.1.1:
Would remove:
c:\users\merej\miniconda3\envs\py3_pcse\lib\site-packages\tornado-5.1.1.dist-info\*
c:\users\merej\miniconda3\envs\py3_pcse\lib\site-packages\tornado\*
Proceed (Y/n)? y
Successfully uninstalled tornado-5.1.1
(py3_pcse) C:\Users\merej>pip install tornado
Collecting tornado
Using cached tornado-6.2-cp37-abi3-win_amd64.whl (425 kB)
Installing collected packages: tornado
Successfully installed tornado-6.2
This Jupyter notebook: https://github.com/ajwdewit/pcse_notebooks/blob/master/01%20Getting%20Started%20with%20PCSE.ipynb doesn't say anything about a kernel so perhaps I installed pcse into the wrong place. My installation passes all of the tests that are listed in the user guide using the miniconda terminal. I saw that this may be a problem with the version of pip that I used to install it since pcse uses python version 3.8; However, I believe that I am using the correct version of pip.
(py3_pcse) C:\Users\merej>pip --version
pip 22.2.2 from C:\Users\merej\miniconda3\envs\py3_pcse\lib\site-packages\pip (python 3.8)
(py3_pcse) C:\Users\merej>python --version
Python 3.8.13
Then I thought it may be a path problem so I made a python path in jupyter notebook using the path given by using python in the miniconda terminal but that also did not work.
(py3_pcse) C:\Users\merej>python
Python 3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcse
>>> pcse.__path__
['C:\\Users\\merej\\miniconda3\\envs\\py3_pcse\\lib\\site-packages\\pcse']
My level of understanding of all this is relatively low so feel free to explain anything you might find helpful.
Thanks!
tl;dr: You want to import pcse, but your jupyter kernel cannot yet do that.
You have correctly diagnosed this as being a virtual-environment issue.
And you're using conda, so the battle is half won already!
You chose to name your conda environment "py3_pcse", a perfectly good name.
That environment contains both PCSE and Jupyter dependencies.
Start by trying this in the base environment:
$ python -c 'import pcse'
Notice that, unsurprisingly, it fails.
Now $ conda activate py3_pcse, repeat the import, notice that it (silently) succeeds.
Here is the critically important piece.
While the environment is still active,
start the kernel with $ jupyter notebook
If the cPython interpreter could access pcse,
then the jupyter kernel will be able to, also.
Verify, by importing within a cell.

Why is occuring an error regarding to the boundary dataset file in Basemap in Python? [duplicate]

I have the same problem as this post:
Declaring a var usable by another function using a import in a secondary script, but the answer does not work on my side.
For context: basemap and basemap-data-hires are installed, yet when using resolution = 'f' it triggers the following error:
OSError: Unable to open boundary dataset file. Only the 'crude' and 'low',
resolution datasets are installed by default.
If you are requesting an, 'intermediate', 'high' or 'full'
resolution dataset, you may need to download and install those
files separately with
conda install -c conda-forge basemap-data-hires.
Here is the conda list output:
C:\Users\AlxndrLhr>conda list
# packages in environment at C:\Users\AlxndrLhr\Anaconda3\envs\map:
#
# Name Version Build Channel
basemap 1.2.2 py39h689385a_5 conda-forge
basemap-data 1.3.2 pyhd8ed1ab_0 conda-forge
basemap-data-hires 1.3.2 pyhd8ed1ab_0 conda-forge
As you can see, basemap-data-hires is present. I tried installing it in the base environment of conda, didn't work either.
Before basemap 1.3.0, the library was packaged in conda-forge by splitting the heavy data files into a separate basemap-data-hires conda package (and whose files were installed in the share folder).
Since basemap 1.3.0, a complete reorganisation of the basemap package has been done upstream by splitting the library into basemap, basemap-data and basemap-data-hires. These three packages are Python packages and get installed in the corresponding Python site-packages folder. This new structuring is propagated to the conda-forge packages.
Your installation is mixing the old basemap conda package (pre-1.3.0) with the new basemap-data-hires conda package (post-1.3.0). You can solve the issue by pinning versions during installation, either the following to install the latest basemap:
conda install "basemap>=1.3.0" "basemap-data-hires>=1.3.0"
or the following to install the pre-1.3.0 version:
conda install "basemap==1.2.2" "basemap-data-hires==1.2.2"

Jupyter notebook: The kernel appears to have died. It will restart automatically [duplicate]

I have create this simple env with conda:
conda create -n test python=3.8.5 pandas scipy numpy matplotlib seaborn jupyterlab
The following code in jupyter lab crashes the kernel :
import matplotlib.pyplot as plt
plt.subplot()
I don't face the problem on Linux. The problem is when I try on Windows 10.
There are no errors on the jupyter lab console (where I started the server), and I have no idea where to investigate.
Update 2021-11-06
The default pkgs/main channel for conda has reverted to using freetype 2.10.4 for Windows, per main / packages / freetype.
If you are still experiencing the issue, use conda list freetype to check the version: freetype != 2.11.0
If it is 2.11.0, then change the version, per the solution, or conda update --all (providing your default channel isn't changed in the .condarc config file).
Solution
If this is occurring after installing Anaconda, updating conda or freetype since Oct 27, 2021.
Go to the Anaconda prompt and downgrade freetype 2.11.0 in any affected environment.
conda install freetype=2.10.4
Relevant to any package using matplotlib and any IDE
For example, pandas.DataFrame.plot and seaborn
Jupyter, Spyder, VSCode, PyCharm, command line.
Discovery
An issue occurs after updating with the most current updates from conda, released Friday, Oct 29.
After updating with conda update --all, there's an issue with anything related to matplotlib in any IDE (not just Jupyter).
I tested this in JupyterLab, PyCharm, and python from the command prompt.
PyCharm: Process finished with exit code -1073741819
JupyterLab: kernel just restarts and there are no associated errors or Traceback
command prompt: a blank interactive matplotlib window will appear briefly, and then a new command line appears.
The issue seems to be with conda update --all in (base), then any plot API that uses matplotlib (e.g. seaborn and pandas.DataFrame.plot) kills the kernel in any environment.
I had to reinstall Anaconda, but do not do an update of (base), then my other environments worked.
I have not figured out what specifically is causing the issue.
I tested the issue with python 3.8.12 and python 3.9.7
Current Testing:
Following is the conda revision log.
Prior to conda update --all this environment was working, but after the updates, plotting with matplotlib crashes the python kernel
2021-10-31 10:47:22 (rev 3)
bokeh {2.3.3 (defaults/win-64) -> 2.4.1 (defaults/win-64)}
click {8.0.1 (defaults/noarch) -> 8.0.3 (defaults/noarch)}
filelock {3.0.12 (defaults/noarch) -> 3.3.1 (defaults/noarch)}
freetype {2.10.4 (defaults/win-64) -> 2.11.0 (defaults/win-64)}
imagecodecs {2021.6.8 (defaults/win-64) -> 2021.8.26 (defaults/win-64)}
joblib {1.0.1 (defaults/noarch) -> 1.1.0 (defaults/noarch)}
lerc {2.2.1 (defaults/win-64) -> 3.0 (defaults/win-64)}
more-itertools {8.8.0 (defaults/noarch) -> 8.10.0 (defaults/noarch)}
pyopenssl {20.0.1 (defaults/noarch) -> 21.0.0 (defaults/noarch)}
scikit-learn {0.24.2 (defaults/win-64) -> 1.0.1 (defaults/win-64)}
statsmodels {0.12.2 (defaults/win-64) -> 0.13.0 (defaults/win-64)}
sympy {1.8 (defaults/win-64) -> 1.9 (defaults/win-64)}
tqdm {4.62.2 (defaults/noarch) -> 4.62.3 (defaults/noarch)}
xlwings {0.24.7 (defaults/win-64) -> 0.24.9 (defaults/win-64)}
The issue seems to be freetype
Downgrading from 2.11.0 to 2.10.4 resolved the issue and made the environment work with matplotlib
Went to post a bug report and discovered there is [Bug]: Matplotlib crashes Python #21511
For anybody that downgrading to freetype=2.10.4 didn't work. In my case the issue happened after installing the new version of scikit-learn=1.11 from conda-forge channel. After trying out many options the following worked for me:
reinstall numpy from main/pkg to conda-forge channel
reinstall mkl package conda -c intel mkl
reinstall matplotlib=4.3 from conda-forge
It's quite a drastic measure, since you have to reinstall all dependecies that rely on NumPy (Pandas, TensorFlow etc.), but it was the only one that worked for me.
I had the same issue and after a fair amount of investigation and troubleshooting, the fix was pretty straight forward:
conda update -c anaconda numpy
conda upgrade -c conda-forge matplotlib
After that it ran fine and my visuals plotted without issue.

Anaconda - can't install package offline after downloading it

I'm trying to install some packages on a remote machine (with GPUs) that is not connected to the internet.
(Some people have suggested I should be using Docker and I may well do that but here's one last chance to get this working).
FYI: I'm following the instructions here.
What I've done so far:
Downloaded Anaconda Anaconda3-2019.03-Linux-x86_64.sh file and installed it on the remote machine
$ conda --version
conda 4.6.14
Then downloaded the desired package from here and moved it to the remote machine.
$ ls pkgs-for-anaconda/linux-64/*tensorflow*
pkgs-for-anaconda/linux-64/tensorflow-gpu-1.9.0-hf154084_0.tar.bz2
Setup a new channel which is the file path on the local file system.
$ conda config --prepend channels file:///home/billtubbs/pkgs-for-anaconda
Excerpt from config to confirm this worked:
channels:
- file:///home/billtubbs/pkgs-for-anaconda
- defaults
Install the package
$ conda install pkgs-for-anaconda/linux-64/tensorflow-gpu-1.9.0-hf154084_0.tar.bz2
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Index the packages
$ conda index pkgs-for-anaconda/
Subdir: noarch: 100%|████████████████████████████████████| 2/2 [00:00<00:00, 81.80it/s]
(base) [billtubbs#localhost ~]$ ch: 0it [00:00, ?it/s]s]05 [00:00<00:00, 750741.03it/s]
Is the issue that it looked in no noarch instead of linux-64?
Try to install the package
When I use the following to create a new environment with the desired package:
$ conda create -n tf tensorflow-gpu
I get:
Collecting package metadata: done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- tensorflow-gpu -> _tflow_190_select==0.0.1=gpu
- tensorflow-gpu -> tensorflow==1.9.0
Current channels:
- file:///home/billtubbs/pkgs-for-anaconda/linux-64
- file:///home/billtubbs/pkgs-for-anaconda/noarch
- https://repo.anaconda.com/pkgs/main/linux-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/free/linux-64
- https://repo.anaconda.com/pkgs/free/noarch
- https://repo.anaconda.com/pkgs/r/linux-64
- https://repo.anaconda.com/pkgs/r/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
What I don't understand is that it shows my channel exists. And it even seems to be looking for the right version (1.9.0). But it says it can't find it.
Just to confirm, I did the following:
$ conda search tensorflow-gpu==1.9.0
Loading channels: done
# Name Version Build Channel
tensorflow-gpu 1.9.0 hf154084_0 pkgs-for-anaconda
tensorflow-gpu 1.9.0 hf154084_0 pkgs/main
Anyone know what I am doing wrong?
UPDATE:
Here is some of the output from
$ conda list --show-channel-urls
...
sympy 1.3 py37_0 defaults
tblib 1.3.2 py37_0 defaults
tensorflow-gpu 1.9.0 hf154084_0 file:///home/billtubbs/pkgs-for-anaconda
terminado 0.8.1 py37_1 defaults
testpath 0.4.2 py37_0 defaults
I will recommend you that you uninstall the current version of anaconda that you have, when I downloaded the last version of anaconda i got some problems, I remenber that I could'nt install for example tensorflow or matplotlib..
The best version to work with tensorflow or matplotlib is having one anaconda with python 3.6. Try to install Anaconda3-4.4.0-Windows-x86_64 or Anaconda3-4.4.0-Linux-x86_64.sh which was released in 2017-05-26.
Anacoda versions
And then try to install tensorflow, matplotlib, pandas, numpy but before run
conda update conda
To update some packages of anaconda.
And you will install those the packages/libraries without problems,
Best Regards.
PD: I also tried to install docker however I got more problems than using python with pip, that's why I think anaconda is the best solution.

Import Error Pythonnet Window 10

Environment
Pythonnet version: 2.4.0.dev0, installed from Master
Python version: Python 3.6.6, Anaconda 3
Operating System: Window 10, 64 bit
Using virtual studio 2017 Community
Details
I had virtual environment set up.
1) pip list
(py36) C:\Users\User\Desktop>pip list
Package Version
--------------- ----------
certifi 2018.8.13
click 6.7
cycler 0.10.0
kiwisolver 1.0.1
matplotlib 2.2.3
mkl-fft 1.0.4
mkl-random 1.0.1
numpy 1.15.0
Pillow 5.2.0
pip 18.0
pyparsing 2.2.0
PyQt5 5.11.2
PyQt5-sip 4.19.12
python-dateutil 2.7.3
pythonnet 2.4.0.dev0
pytz 2018.5
scipy 1.1.0
setuptools 40.0.0
six 1.11.0
visbrain 0.4.2
vispy 0.5.3
wheel 0.31.1
wincertstore 0.2
2) path and pythonpath before python initialize.
string path = #"D:\Anaconda3\envs\py36;" + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONHOME", #"D:\Anaconda3\envs\py36", EnvironmentVariableTarget.Process);
// initialize python engine
PythonEngine.Initialize();
3) set Amaconda in %PATH%
4) python path
(py36) C:\Users\User\Desktop>python --version
Python 3.6.6 :: Anaconda, Inc.
ReadMe works fine.
but when i typed like this in my C# program
using (Py.GIL())
{
// import vispy
dynamic myVispy = Py.Import("vispy");
Console.WriteLine("hi vispy");
}
error message below
Python.Runtime.PythonException: 'ModuleNotFoundError : No module named 'vispy''
stack trace :
Python.Runtime.PythonException
HResult=0x80131500
Message=ModuleNotFoundError : No module named 'vispy'
Source=Python.Runtime
StackTrace:
would like to know how to solve this ?
Thank You.
See this answer: Python.NET does not work with Anaconda or Miniconda. You need a fresh python install.

Categories