plotnine: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail - python-3.x

I am trying to use plotnine to generate some graphs. I import the required libraries:
from plotnine import *
from plotnine.data import mpg
And then, if I run the following code in PyCharm I get a Warning message, the window plot
shows a "No answer" message and I am forced to restart the python terminal:
(ggplot(mpg) # defining what data to use
+ aes(x='class') # defining what variable to use
+ geom_bar(size=20) # defining the type of plot to use
)
<ggplot: (150517199824)>
C:\Users\alvaromc317\miniconda3\envs\general\lib\site-packages\plotnine\ggplot.py:363: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
However, If I start a python terminal from windows cmd terminal and run the same script as before, I get no error message and I see the plot with no problem.
What is happening and how do I get to use plotnine in pycharm?
In case it is needed, I work using a Windows 10 machine and python 3x based on miniconda.

I'm having a similar problem, but on MacOS using the commercial addition of PyCharm.
From this github issue and this JetBrains issue, it looks like it might be related to a PyCharm bug.

Related

Linux Ubuntu how to start standard application scribus from python eclipse anaconda

I edited my question, hope it is described better now.
I am working on a software that gives me a nice PDF with lots of matplotlib graphics, depending on the data I get.
So think of a database of pages and then the software decides which pages are chosen and filled with changed images, The text stays the same.
So for instance for data1 I get page1-4 and page7 and page 9. For data2 I get page1-4 and page6. Saved as PDF. I am doing this manually with Quark which needs to be changed. I hope I can figure out the scripting to do so.
But for starters I cant start scribus from the developing enviroment. Eclipse Anaconda on Ubuntu.
import subprocess
subprocess.run('scribus')
works fine in terminal, but gives me an error in Eclipse which I cant figure out.
File "/home/b256/anaconda3/envs/test/lib/python3.7/site.py", line 178
file=sys.stderr)
^
SyntaxError: invalid syntax
This seems to be some Python 2 error in the site.py file
???? Is this some anaconda python path error ??
It's not really clear to me, what you want to achieve, but you're welcome to have a look at a script of mine:
https://github.com/aoloe/scribus-script-repository/blob/master/imposition/imposition.py
This is probably a bit more complex than what you are trying to achieve:
the script gets started from the terminal,
if it notices that it has not been started from inside of Scribus (the exception on import scribus)...
... it starts Scribus with itself as the Script to be run.
the script runs again, this time from inside of Scribus...
... now there is no exception when importing scribus and the body of the script runs.
Of course, it's simpler if you start a script that launches Scribus with other scripts.
For you the most important line is probably:
call(['scribus', '-g', '-py', sys.argv[0]] + arguments + ['--', file])
It's starting Scribus from Python
with as little GUI as possible (-g) and
launches the script sys.argv[0]
with a few arguments and
after the -- tells Scribus what file to open.

Spyder - disable warnings inside Spyder Console

I use Spyder (4.1.5) as my python editor. When I run the code it shows a million workings that make it impossible for me to really focus on the output of the code. I read a lot of posts here on stackoverflow (see for example: Hide all warnings in ipython ) and it seems they all suggest to add
warnings.filterwarnings("ignore")
This for sure does not work.
For example, one of the many warnings printed to console many times is this one:
C:\...\Utils.py:2831: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
However, I also have this line of code at the very beginning of the script:
warnings.filterwarnings("ignore", category=FutureWarning)
Still, no luck in disabling it.
import warnings
warnings.filterwarnings("ignore")
worked for me using Spyder 5 and Python 3.8.10

Pyside to build PyQT designer 4 UI file always results in error

Using Pyside-uic -o pythonfilename.py uifilename.ui to convert my PyQT4 designer GUI to python code. Seems to build just fine with no errors, but when I run the file, it consistently crashes, with type errors I can't solve.
First error gave me trouble because I set a "max size". When I removed the max size, the error changed to be a problem with the palette. I removed the palette settings, and replaced it with style sheets, and now it's giving me the error:
"TypeError: QWidget.setFont(QFont): argument 1 has unexpected type 'PySide.QtGui.QFont'"
I doubt there are this many problems with using Pyside to build PyQT UI files(because it seems to be a pretty standard way of doing it), so that leaves me to believe it's something i'm doing.
**Just a note with a bit more info.
This is software we've been using for some time, and the existing UI was built using this exact method. I inherited the file, and was asked to update the UI, and left with instructions on how to do it. I updated the existing ui file, saved it out, and ran the "Using Pyside-uic -o pythonfilename.py uifilename.ui" command. No errors from the build, but %100 of the time i've tried using this method, it has failed.
I tried googling the answer for hours, and proposed the question to other people.
I solved the issue. After pyside spits out the new python file (built from the UI file), theres a line of code at the beginning that will say something along the lines of "from PySide import QtCore, QtGui"
"PySide" has to be changed to "PyQt4".

Python curses getmaxyx() always returning same value on windows

I am having trouble with using the python curses module for windows. I have used the wheel found here to get a script I had written on my mac to run on my desktop. For now, the script just displays a border around the window using the screen.border() method and another line across the whole width of the display. I displayed the bar across the screen using this:
dimensions = screen.getmaxyx()
screen.addstr(dimensions[0]/2, 0, "-"*dimensions[1])
I ran this in a loop, resetting dimensions each time and using getch to check for a curses.KEY_RRESIZE and then running screen.erase() to allow me to resize the window and the script will still work. When I ran this on windows after installing the wheel for python 3.7 (win32 because the amd64 one gave an error) I found that screen.getmaxyx() always returned the same value: the initial screen size, and never changed when I resized the window. I appreciate any help if anyone knows a way to fix this issue, or if I simply cannot use curses on windows, an alternative library for windows. Thank you!
Call resize_term(0, 0) after you get a KEY_RESIZE. (I’m not sure of the exact Python mapping.)
That ("on windows") is probably using PDCurses, which doesn't have a way to automatically update the screensize (e.g., as done with POSIX-based ncurses's SIGWINCH handler). Rather, it detects the window-size change and the application can call is_termresized to decide whether to tell the library to change the data structures to match using resize_term.
The python wrapper doesn't use that.

Can a python module be imported without installing

Is this possible that a module is imported without installing the same. If no then why is my spyder IDE is showing a warning on the line where it is written import nltk even when nltk is not installed
Spyder runs a static analysis on the code you have in the Editor to offer hints and errors about it.
Since the analysis is static, it means Spyder doesn't run your code to perform it. In your case it simply detects that you have a line like
import nltk
but that there's no other use or call to nltk (for example, with a code like nltk.pos_tag(tokens) or something like that).

Resources