How to get pylab to work in eclipse pydev? - eclipse

It seems interactive plotting using pylab/matplotlib does not work in pyDev. After for example:
pylab
x=linspace(0,10,1000)
plot(x,x*x)
nothing is plotted in the figure window, and the window is not responding.
Is there any way to get pylab to work properly in pyDev? I am using matplotlib version 1.2.0 and the backend is TkAgg.

Related

I'm on VSC and I had to change the python version using the different environments, now when I import modules VSC says they aren't installed

I needed to change to a different python version because one of my imports had randint in it from random and my lanky python 3.8.10 doesn't like it.
I'm installing my modules for my discord bot as I would usually do, but now it hits me with
Import "discord" could not be resolved
(same for all other modules I've tried importing)
...
Using pip freeze I can see it's there, it's installed, but VSC refuses to recognise it.
I've tried going back to my original 3.8.10, and it works perfectly, it just means I need to remove the faulty import and then my code won't work.
I've tried using all the other interpreters but still, nothing happens. Only on 3.8.10
Any help?

Issue with Pylance and matplotlib

I have looked at these problems online but I don't seem to be able to find a good answer.
System details:
Mac OS BigSur 11.6 on a M1 MacBook Pro
Installed miniforge as discussed here
Installed VSCode for Mac
I have these two following (unrelated?) problems when using jupyter notebook:
PyLance does not resolve imports like numpy etc. I see that os or sys are recognized and resolved but pretty much nothing else is. The kernel used by the jupyter notebook is the correct one. Indeed I am able to run the code with no issues but I get all these unrecognized imports.
I am not able to run the jupyter notebook with %matplotlib notebook. I can run with %matplotlib inline, but then I am not able to see the widgets to zoom in etc. To be more precise, if I try to plot in a cell then after it I see the following:
either nothing or
the following <IPython.core.display.HTML object>
This is achieved by clicking on the symbol </> and changing the rendered from html to text.
I am wondering if there is some issue with my installation of python and jupyter on the M1 or it is a VSCode issue. Any suggestion on where to look into the problem(s)?

how do I fix python file closing automatically when importing certain libraries?

So I am trying to run some scripts just by opening the python file directly (not running through pycharm). However, when I import certain libraries (such as numpy or matplotlib) the terminal will close automatically, even if the program is waiting for user input. All of these scripts run without error in pycharm.
Here is an example of some imports that don't close the window automatically:
import tkinter as tk
import math as m
input('press enter to return')
Here is an example of some imports that do close the window automatically:
import numpy as np
import matplotlib as m
input('press enter to return')
What is going on here? I am relatively new to coding and so I think I might be missing something fundamental.
This might be because anaconda has not been installed to your system path, it's important to have python interpreter and IDE being set to PATH especially when you are working with libraries that are not pre-installed
Hope it cleared your doubts, if any errors, do let me know
Cheers

Display of music21, musicXML PNG objects using iPython Notebook/Enthought Canopy

I am experimenting with the music21 library, in preparation for a Machine Learning project that involves genre classification and categorization. I and following some tutorials available here. I am using MuseScore as my MusicXML program, and I am trying to run the whole thing from iPython.
Although I can run the some of the turtorials from the terminal, some elements don't seem to run well from inside iPython. For example:
In [3]: sBach.show()
Out[3]: <music21.ipython21.objects.IPythonPNGObject at 0x10da0aa10>
The line above shows that the PNG object is created, but not displayed. The expected output for 3 above is the following:
Experimenting with the following iPython command, I get a placeholder for an image, but not image.
In [6]: %load_ext music21.ipython21.ipExtension
In [7]: sBach.show()
I can't find any problem with my MusicXMLPath. This tutorial refers to the use of musc21 with Anaconda, but all my developments is done with Enthought, so I prefer not to run another virtual environment to use music21 with iPython.
Is there any way to run music21 in an Enthought/iPython notebook?
I have been grappling with this issue myself. ... Have you set your musicxmlPath in music21? If you have not, it's done via environment.set(key, value). You can query for available keys with environment.keys(). I hope this isn't too simple an answer, but it cleared up the problem for me.
This should be in the iPython music21 documentation somewhere, my apologies: iPython in music21 requires Lilypond to be installed for images to be generated within the notebook itself. There hasn't been (and won't be until MuseScore 2.0 is released) a way using MusicXML to generate PNG images of scores directly.
Edit: 2015 July; music21 2.0 w/ MuseScore 2 will generate the PNG images with MuseScore if it is installed and fallback to Lilypond if it is not installed.
If not yet tried, some steps to isolate the cause of the problem:
1) Update to the latest Canopy (Edit: currently 1.4.1) (might help this, will help generally, won't hurt).
2) Change the Pylab backend in Canopy's IPython shell to "Inline (SVG)", via Preferences / Python. (The default Qt backend in that shell conflicts with music21's use of the tkinter library.)
3) Test your script in that shell rather than in the notebook.
4) Ensure that Canopy User Python is your default Python in a Terminal window, as described here.
5) Test your scripts inside of plain ipython terminal (from Terminal, type ipython).
6) Test in ipython terminal in pylab mode (ipython qtconsole --pylab=inline).
7) Test your scripts inside of ipython notebook running in a regular browser (from Terminal, type ipython notebook, and/or ipython notebook --pylab=inline).
Had similar issues before. It's the same problem when people try to use plot function in ipython/jupyter notebook. You need to call
%matplotlib inline
For me the issue was solved by uninstalling the snap version of musescore and installing it from ppa:mscore-ubuntu/mscore3-stable via https://launchpad.net/~mscore-ubuntu/+archive/ubuntu/mscore3-stable

"Undefined variable from import" when importing numpy in eclipse pydev

I get "Undefined variable from import" error in Eclipse 3.7.2 PyDev 2.7.1 on Linux Mint Maya (Cinnamon) whenever I import a module from numpy. The problem only arises when importing numpy; other modules work just fine.
Info: numpy is compiled against the Intel MKL libraries. Python 2.7.3 [GCC 4.6.3]
example:
import numpy as np
a = np.array([1, 2])
Error message in PyDev editor:
"Undefined variable from import: array"
I get similar errors for other numpy submodules.
The code runs properly either within Eclipse or in a terminal. The problem is only present in the Eclipse-PyDev editor.
The LD_LIBRARY_PATH has to contain paths to the MKL libraries. Even if LD_LIBRARY_PATH is set properly, it has to be explicitly specifed in Eclipse under Window > Preferences > Interpreter - Python, under the "Environment" tab on the right hand side. Add a new variable called "LD_LIBRARY_PATH" and paste the content of $LD_LIBRARY_PATH.
Once it is done, errors will only disappear from your code if a line is added to the code which uses a numpy object so that imports are checked again.
I managed to fix it by updating the Phyton interpreter in Eclipse. Just click on Apply button after successfully installed Numpy module.
Are MKL libraries and numpy the same thing? #user1898039's answer didn't make sense to me (I'm not sure what path I should use for that property.
I found another way to fix this issue - I checked the python command line to see if numpy was installed there by calling:
>>> import from numpy *
It was not. So, despite the fact that numpy was showing up in PyDev under the "Forced Builtins" tab in the Python Interpreter properties, it wasn't available to python from the command line and I imagine this caused the issue inside PyDev.
So, I fixed the problem by going to the numpy site and installing the newest version for windows. Technically I went to some other site that had a AMD64 version of the installer for windows, buy you know, same same. After that I tried to get the PYTHONPATH variable to recalculate all the libraries (this may have been unnecessary), but errors were still showing in the file on all the calls to array(). I did an autocomplete on the numpy package to get the list of functions, selected array() from that list, and all of the sudden all the errors cleared and everything is fine now.
I was able to resolve this by adding the following path to PYTHONPATH (Pydev => Python Interpreters => select an Interpreter => Libraries):
/usr/local/anaconda/lib/python2.7/lib/lib-dynload
installed packages (among others):
conda==3.10.1
numpy==1.9.2
scipy==0.15.1
I occasionally see these errors for pandas objects, after re-starting Eclipse, even though I of course have 'import pandas as pd' at the top of my file.
I've discovered a simple workaround: I simply delete the import statement, save the file, paste it back in and re-save. The errors go away!
I'm on this version of Eclipse:
Eclipse for PHP Developers
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600