Matplotlib hangs during instantiation on Pixelbook - python

I am trying to set up a python3 development environment on my Pixelbook.
I enabled native linux app support on it by switching to developer branch, so now I have a working bash shell with apt.
I was able to install gvim and python3.5.3 and pip. I installed numpy, scipy, pandas and matplotlib fine. All the other packages work smoothly, and I can import matplotlib, but as soon as I try to call any method from matplotlib it hangs my shell and never returns.
Here is a simple scripts I use for testing:
import scipy as sp
import matplotlib.pylab as plt
t = sp.arange(0, 10, 1/100)
plt.plot(t, sp.sin(1.7 * 2 * sp.pi * t) + sp.sin(1.9 * 2 * sp.pi * t))
plt.show()
I try to run it like this, but it never returns and Ctrl+C doesn't help either:
Command output
I tried using a different backend like this:
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
It doesn't help either.
Some people suggest using matplotlib.ion(), but it didn't change anything either.
I found this thread where someone was also having a hard time using matplotlib on a pixelbook.
The solution proposed there was to install spyder, so I did, like this:
sudo pip3 install -U spyder
This didn't help either.
It seems to me that matplotlib cannot find the graphics back end on my machine. I am running crouton and as I mentioned before gvim installed just fine. This is after the google announcement of support of linux native apps on chromebooks, so I am not running in a VM, this is stock chrome os moved to dev branch and switched to enable linux.
I am wondering if I need additional X11 backend installed separately, but I checked google documentation for installing Android Studio on Pixelbook, and it didn't mention any additional graphics installations, just "enable linux and install the linux tgz package". I would really appreciate some pointers.

Related

Unable to import 'matplotlib.pyplot'

I know this question is asked a lot, I searched for the last three hours for an answer, but couldn't solve my problem.
As soon as I try to:
import matplotlib.pyplot as plt
my Visual Studio Code IDE tells me that: Unable to import 'matplotlib.pyplot'
My current version of Python is:
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
as you can see, I used the Anaconda package, hence matplotlib should be included. I am Using Mac OS 10.15.2
If I enter
import matplotlib.pyplot as plt
it does import that, however, as soon as I try a basic example, like
x = [1,2,3]
y = [2,4,1]
plt.plot(x, y)
I obtain:
[<matplotlib.lines.Line2D object at 0x10c23d950>]
And a blank token in my Dashboard pops up, which I can only force to quit.
In the course of trying to solve this problem, I tried anything I saw that was related to this topic, although I did not understand everything of it. I hope I did not make a real damage.
My last step was completely deinstalling anaconda and reinstalling.
Thanks for taking your time!
The module can be imported, but your IDE says module not found, means your linter (vscode uses pylinter) is not configured correctly.
Start PyLint from correct anaconda environment in Visual Studio Code
First you need to install package matplotlib using conda console in your project
conda install -c conda-forge matplotlib
You also can install package using PIP
python -m pip install -U matplotlib
And Finally import your package in your source code
import matplotlib.pyplot as plt
Or another Way you can import
from matplotlib import pyplot as plt
Having come here with this error myself, especially if you're using VS Code you need to make sure that the version of Python you're running in VS Code is the same one that's running on your OS. Otherwise, you can conda install or pip3 install all you want into the OS, but VS Code and Jupyter Notebooks won't know anything about those modules. There are a few ways to figure this out, but mostly it's making sure that the Python version you see when typing python --version in the terminal matches the interpreter shown in the top-right corner of your VS Code window.

New To Visual Studio Code, having problems with pandas/numpy

I normally use PyCharm for python coding, but just for the heck of it, I tried to use Visual Studio Code today, and I'm having some problems.
So I followed the steps shown in the "Getting Started with Python in VS Code" page, and I copied this to my new python project:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x = np.linspace(0, 20, 100) # Create a list of evenly-spaced numbers over the range
plt.plot(x, np.sin(x)) # Plot the sine of each x point
plt.show() # Display the plot
just to test if it works well, and for some random reason, whenever I run this code through terminal/cmd in VSCode, I get this:
ImportError: Missing required dependencies ['numpy']
BUT when I use the Debug Mode, it seems to work perfectly fine.
similar thing happened when I tried to run my previous projects through VSCode. So I thought maybe it was just the problem with my environment, so I changed it to the one where I have my tools installed, but nope, I still got the error.
I tried uninstalling then installing again and that didn't work as well.
I Seriously don't know what's happening right now. Why does it work well in Debug Mode but not in terminal/cmd? does anyone know what to do in this situation?
Thanks!
...In Python, packages are how you obtain any number of useful code libraries, typically from PyPI. For this example you use the matplotlib and numpy packages to create a graphical plot as is commonly done with data science. (Note that matplotlib cannot show graphs when running in the Windows Subsystem for Linux as it lacks the necessary UI support.)
Return to the Explorer view (the top-most icon on the left side, which shows files), create a new file called standardplot.py, and paste in the following source code:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x = np.linspace(0, 20, 100) # Create a list of evenly-spaced numbers over the range
plt.plot(x, np.sin(x)) # Plot the sine of each x point
plt.show() # Display the plot
Tip: if you enter the above code by hand, you may find that auto-completions change the names after the as keywords when you press Enter at the end of a line. To avoid this, type a space, then Enter.
Next, try running the file in the debugger using the "Python: Current file" configuration as described in the last section. (If you still have "stopOnEntry": true in that configuration, you need to select the run command again to continue.)
Unless you're using an Anaconda distribution or have previously installed the matplotlib package, you should see the message, "ModuleNotFoundError: No module named 'matplotlib'". Such a message indicates that the required package isn't available in your system.
To install the matplotlib package (which also installs numpy as a dependency), stop the debugger and run Terminal: Create New Integrated Terminal from the Command Palette (⌃⇧(Windows, Linux Ctrl+Shift+))). This command opens a command prompt for your selected interpreter. Then enter the following commands as appropriate for your operating system (commands may require elevation if the Python interpreter is installed in a protected area of the file system):
Note: If you are unable to install the package or encounter other problems, please file an issue on GitHub so we can help you investigate.
# Don't use with Anaconda distributions because they include matplotlib already.
# macOS
sudo python3 -m pip install matplotlib
# Windows (may require elevation)
py -3 -m pip install matplotlib
# Linux (Debian)
sudo apt-get install python3-tk
python -m pip install matplotlib
from: https://code.visualstudio.com/docs/python/python-tutorial
Got this error and was able to fix it by running conda init in the Python Debug Console terminal, and then closing the terminal before starting a new debug session.
In VS Code undee Windows open Terminal -> New Terminal and run
pip3 install pandas
and then
pip3 install matplotlib
While installing pandas, numpy will be installed as well
I believe it may have something to do with the PATH variables. I just had the same problem in Windows 10 and found out that if I launch VS Code through an anaconda prompt it works just fine, no need to mess around with the PATH variables.
So, instead of opening VS Code through the start menu, just open an anaconda prompt (or anaconda shell), cd to your directory and type code .. That solved my issue.

Python Mayavi In Virtual Environment

I am facing 2 issues while trying to use mayavi on Mac OS in virtual python environment.
Running Mayavi2 from command line throws following message only and does nothing else
"This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac."
executing from mayavi import mlab throws the same message as in 1.
Using from mayavi import mlab in eclipse ImportError: cannot import name mlab
After a great hassle I have managed to install mayavi but now I can't execute any of the sample codes involving mlab
vtk is installed. import mayavi has no problem, command line or Eclipse.
It seems you are using the python build provided by Apple in Mac OS. This is apparently not compatible. You should try to use one of the versions from python.org, which are framework builds. Please note that you will have to install your dependencies again.

Mayavi has stopped working, crashes Python Jupyter notebook

I had installed Mayavi package in Anaconda Python on my Windows 7 machine. It was working until today. Today, it has stopped working, and crashes my Python Jupyter notebook. For example, the following simple script causes "Python has stopped working" message and Python kernel death:
import numpy as np
import mayavi
from mayavi import mlab
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
sf = mlab.pipeline.scalar_field(s)
The versions of Anaconda, Python, and Mayavi are 4.1.1, 3.5.2, and 4.5. Additionally the versions of numpy, traits, and vtk (required packages for Mayavi) 1.11.1, 4.6, and 7.0.0. I tried updating Mayavi and all these packages, and that did not resolve the issue. Can someone please help?
Apparently the issue is that Mayavi display does not work over a remote desktop connection, which is what I was working through yesterday! I have not clue why, and am curious to know if someone has an answer. I'm logged into the machine directly today, and it works.

pyplot while using X11 forwarding

I'm trying to setup my remote working environment so that I can use matplotlib.pyplot under ipython. My local machine and remote machine are both MAC OSX Mavericks. I've tried xeyes and it works properly so I think my X11 forwarding works fine. However, when I try functions in matplotlib.pyplot it didn't show any error message but I didn't see any figure either.
I know it's about which backend to use and I've tried using ipython --pylab=tk but didn't work. Tried to install pygtk but can't manage to install a dependency py2cairo (seems to be an open issue). Any other thoughts? Thanks.
How did you "try functions in matplotlib.pyplot"?
The following works for me
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()

Categories