linting and intellisense on Visual Studio Code - python

I installed ms-python.python. Normally I use Atom and I switch to VS Code for trying.
I have 2 questions :
I set linter to flake8 : Is it possible to verify in real time like Atom the python syntax or only possible when I save the file ?
Also, Atom show the content of vars : vars in Atom. There is a way to do the same thing on Visual Studio Code ? vars in VSC

Linting on change is not implemented, but there is a feature request for it
I have no issues seeing attributes, but I'm running on the development build of the extension so whatever issue you're running into may not be publicly released quite yet

Related

IntelliSense in Visual Studio Code not working with python packages

I am fairly new to python. So I installed python and my editor is Visual Studio Code. The Intellisense seems to work for this code (extension BeautifulSoup):
enter image description here
But it doesn't work for this:
enter image description here
I tried to restart my computer, but it didn't help.
I have also tried to use virtual enviroments and I also selected the right associated interpreter. To use python in Visual Studio Code, I installed following extensions:
MagicPython
Pylance
Python
Python Extension Pack
Visual Studio IntelliCode
Do you have any Idea why my Intellisense is not working for packages?
In VS Code, the "Intellisense" function of Python code is provided by the the Python extension, and the language service provided by "Pylance" provide us with docsing content.
Therefore, it is recommended that you "disable" other extensions to avoid interference between them and affect the use of the "Intellisense" function.
In addition, if it still doesn't work, please reinstall the Python extension and reload VS Code.

Debug python Visual Studio Startup very slow - load module

When start debug from Visual Studio, it takes like 2 minutes to hit the first line of python code. Apparently Visual Studio is busy loading python modules.
python.exe' (Win32): Loaded 'C:\ProgramData\Anaconda3\python.exe'. Symbols loaded.
'python.exe' (Win32): Loaded 'xxxxx'. Cannot find or open the PDB file.
... many more ...
I tried below, no joy:
Tools \ Options \ Debugging
a) Enable Just My Code checked
b) Just-In-Time Debugging - only selected Managed and Script
c) Symbols
unchecked "Microsoft Symbol Servers"
"Load all modules, unless excluded" or "Load only specified modules" (tried both)
https://devblogs.microsoft.com/devops/make-debugging-faster-with-visual-studio/
Reinstall Visual Studio (I tried both Community Edition, Standard Edition)
Reboot my machine three times
Delete all breakpoints
Disable Resharper
Two more observations:
I never had this issue prior to today
Python Interactive Debugger stopped working today - it refuse to print anything!
myDataFrame.head()
print("hello")
Fixed!!
I deleted my Visual Studio solution and project file. Create the python project brand new, all fixed!
Just in case anyone else is looking around,
I also had horrendous debug times (2+ minutes to get to the first line of code).
I was using an Anaconda deployment for numpy/scipy along with pybind11 to interface/debug C code.
I fixed my debug times by using a vanilla deployment of python (3.9.1) and installing the minimal requirements using pip. I believe it was taking so long because visual studio is searching for debug symbols that do not exist. Anaconda does not provide symbol libraries (nor will they according to their forums)
Debug times are now as fast as normal run times (<1s) and I'm no longer dreading hitting the little bug button.
To disable "Enable native code debugging" in the solution properties helped for me.

Exactly similar PyCharm alternative

I am currently using Pycharm. What I like about PyCharm are the following:
Simplicity of creating virtualenvs
Intellisense
GUI package installer
Console (automatically activates the venv)
However, I also lacked the following
intellisense for javascript (I believe they require a paid
license)
I recently tried visual studio but it lacked
GUI package installer
Is there an ide that can give me all the aforementioned features? I need to use this ide for full stack development in Python

Python Visual Studio extension doesn't show errors

I'm used to use VS to code C++ and Eclipse to code python but lately I have tried VS for both languages.
I found something very difficult to understand that while VS autocompletes it doesn't warn you about errors before runtime.
There is no warning regarding non existent variables or methods. I can't believe that VS does not warn about this kind of typical coding issues as it does for C++ code (as every IDE does).
What am I missing?
I tested this with VS2013 and VS2015.
I'm expecting something like:
Thanks
In order to get the python detailed IntelliSense support in VS2015 you have to install python tools for visual studio which provide the following:
CPython, PyPy, IronPython and more
Detailed IntelliSense
Interactive debugging
Integrated with Visual Studio features
Free and open-source
And the best thing, it's completely free.
Just download it from here:
https://www.visualstudio.com/en-us/features/python-vs.aspx
I hope it supports your question.
Update after comment:
You just need to refresh the Database. It works for me. Check to make sure the environment options are set (specifically path variable to PYTHONPATH) and the DB is refreshed.
Sometimes Deleting the __init__.py file in my source root directory did the trick
It seems that with a regular Python installation (2.x or 3.x in 32bit or 64bit) there are limited "warnings" (hovering over an undefined variable gives "unknown type"), but Syntax Highlighting / Intellisense doesn't seem to work.
Intellisense NOT Working:
Getting Intellisense to Work:
After some research I tried installing another Python interpreter for Visual Studio to work with. I went with Iron Python because it is "tightly integrated with the .NET Framework".
Download it from here --> http://ironpython.codeplex.com/downloads/get/970325
After installing IronPython open Visual Studio and set it as the "Default Environment for New Projects". You can set it in "Tools" --> "Python Tools" --> "Python Environments" (or by pressing Ctrl + K + `)
Make sure to refresh the database and Syntax Highlighting will start working. It doesn't seem very thorough, but it is there.
See photo below:

can .ptvs be saftely git ignored?

I'm using visual studio 2013 and the python tools for visual studio.
While setting up the project i've begun adding to the standard VS .gitignore as it doesn't cover the tools. I have a subdirectory labeled .ptvs in my environments folder. Currently it only seems to have logs in it.
Is there any risk that something important ever ends up there? Documentation is lacking in this area.
Thanks in advance.
The Python Tools Visual Studio seems to cache or generate files, logs and DB in the hidden folder .ptvs.
Since those data are generated, you should safely ignore that file and never version its content.
See for instance this discussion around the issue "Visual Studio 2010 freezes with PTVS 2.0RC":
Are you using or can you upgrade to our latest dev build and see if the issue goes away?
You may also want to try deleting the (hidden) .ptvs folder in your virtual environment and recreating the DB from scratch.

Categories

Resources