Issue with Pylance and matplotlib - visual-studio-code

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)?

Related

Pytorch module not found in VSCode

For the life of me I can't get the VSCode integrated terminal to correctly run a simple program that just has import torch in it. I've tried it all. I tried just installing pytorch via conda (I have Anaconda) inside the VSCode terminal, and then running my program inside the VSCode terminal as well. I tried creating a conda virtual environment, activating it, installing pytorch in it, and then running my program using the virtual environment. I tried switching the VSCode python to ('base': conda) and it didn't work. I tried switching the VSCode python to ('pytorch': conda) (I read this somewhere on StackOverflow), but I didn't find this. I tried uninstalling and re-installing the Python extension in VSCode. I tried just running python3 inside the VSCode terminal and seeing if >>> import torch would run, but it doesn't. I tried installing torch with pip or pip3 instead of with conda but it doesn't work, it just tells me that No matching distribution found for torch.
However, outside of VSCode, I can do import torch and it runs correctly. How could I solve this? I would very much prefer to use VSCode and its integrated terminal, but VSCode can't find pytorch for the life of me.
EDIT: Using MacOS Monterey and most updated python extension in VSCode

Regarding "torch" package - with anaconda environment using vscode as editor

I am currently working on project,where I use pytorch as deep learning environment. I have serious problem, that .... "When I use anaconda jupyter notebook terminal to run my *.py files. Then, it run properly. But, when I use the same environment within vs-code via python_interpretor, I can not get result and give me error "torch module can not found".
Can anyone have solution?. Actually, I see the packages using "conda list" and it includes torchvision inside environment. I also tried to install torch in base environment But, it does not work.
Please give me some solution. Thank you for your consideration.

VS code in a jupyter notebook?

I am looking to see if it's possible to run vs code from a jupyter notebook, as in have it as a kernel that I can use to run vs code in the web browser.
https://docs.anaconda.com/anaconda/user-guide/tasks/integration/vscode/
Is this even possible?
So have what appears in anaconda navigator below, appear in the jupyter lab ui below.
I found this.
https://github.com/jupyterlab/jupyterlab-monaco
Although it's "merely a 'proof-of-concept' implementation and nowhere near production status" so not ready for my use case yet. Still it's there for those interested.

Canopy / iPython Notebook Image Issue

I've installed Enthought Canopy 1.3.0.1715 on Max OSX 10.9.2, and updated all packages. All seems to have gone well until trying to create a new iPython notebook. When the notebook opens, none of the buttons for the notebook contain any images (just small 'x''s). II believe this problem is causing other issues in notebooks, but I'd like to get this one fixed first. Has anyone seen this and have a solution / idea? FYI, This works fine starting notebook from the terminal, just not as how Canopy is hosting the notebook.

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