can .ptvs be saftely git ignored? - python

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.

Related

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.

Python Tools for Visual Studio and Unit Tests (PTVS)

Hopefully someone can give me a hand/few pointers.
So I am currently working on some python scripts and wanted to get some tests written.
My environment is as follows:
MS Visual Studio Community 2015, v.14 Update 3
PTVS v.2.2.4 (2.2.40623.00-14.0)
Python 3.5 64-bit Environment
I have some demo tests written in a test class, which have been appearing and disappearing in test explorer under their own will. Currently, I have none showing in Test Explorer, as per the screenshot below...
Several other people seem to be having issues, and the reasons vary from the test settings processor architecture selected, through to clearing the files in the temp folder etc.
I have been pulling out my hair for a few days now, and am looking for your help, cos i'm now bald.
I've tried removing PTVS and reinstalling, updating to latest, changing the test environment, adding and removing Nunit, incase that was conflicting, etc etc etc.
Any help would be greatly appreciated.
Just managed to get this error message to appear, but I do not think it's correct:
OK, so another update:
I decided that I would download VS CE 2013, and then install PTVS 2.2.3.
I opened the solution there, and the tests loaded instantly, and ran first time...
I know that is not a solution to the problem, but at least I can now run my tests and continue working.
Kindest Regards,
Ok, so it seems that PTVS does not fully work with VS2015 Community Edition.
You can run your scripts etc, but it does not integrate with the test explorer properly.
You will need to download VS2013 CE, and PTVS 2.2.2. Then you can run the test explorer and click run all, which will find all your tests, and run properly. Hope this helps someone, as I spent days trying to get VS2015 and PTVS 2.2.4 working with no luck.

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:

Get python modules into Visual studio 2015 Community edition

Simple problem, made difficult of course , by Microsoft. How do I install sqlite3 or Pmw on my Visual Studio Community version of Python. I normally place the files my self into site packages folder. With Visual studio they talk about packet manager but where is it? Can it really be this hard?
Hopefully you have the Python Tools for Visual Studio plugin installed. If not, go to https://github.com/Microsoft/PTVS to get v2.2. You can also check out a PTVS Getting Started tutorial series on YouTube.
Assuming you have PTVS, right click on your Python Environments in your solution. Add Virtual Environment.
Right click on the env and choose Install Python Package.
Install your Python package.
For SQLite3, you place your .db or .sqlite3 file in your project. If you copied it manually in and you want Visual Studio to "see it" in the Solution Explorer, you may need to right click on the solution name and Add Existing Item...
I also recommend you go to "Tools >> Python >> Python Environments" to bring up a pane where you can explore any Python versions or virtual environments available to this solution. You can see which module are installed, if they're out of date, and search the PyPI directly from there.
Just go to your Python/Scripts folder at the command prompt and "pip install ". You may need an administrator command prompt.
If it's a package with binary components (numpy, etc), you can download and install from here (very useful site): http://www.lfd.uci.edu/~gohlke/pythonlibs/ Just be sure to get the version and 32/64 bit that matches your python.exe.
Within VS2015, Tools - Python Tools - Python Environments. Select an environment from the left side, and you'll see an entry one column to the right 'pip'. Select that. There's now a search box where you can type in the package you want. Then scroll down and select "Install package".

Django project won't work with Python Tools Visual Studio

I'm trying to get a Django project working with PTVS. The only reason I'm using it is because I have Azure credits and want to deploy there. In Visual Studio, I go to New Project > Python > Django. I chose "Add Virtual Environment". Here is the screenshot:
After the project is created, this is my solution explorer:
You can see django is definitely installed in the environment. But when I right-click on the app and go to Python > Sync DB, I get a bunch of errors says that
ImportError: No module named django.core.management. All the django package statements are underlined and they can't be imported. Any ideas?
When I go back to create another project and I do "Install into Python 2.7 directory," it works fine. So I don't understand why I can't use the virtual environment.
Go to your Projects folder and delete all the application/projects.
Clean the project directory. (By default this is the PATH: Documents/Visual Studio 2013/Projects
Close all the other IDE's and Programs that might be using your
python interpreter.
Set no-proxy in case you are using some proxy settings because it
will prevent Visual Studio from downloading and installing the required
packages.
You might prefer restarting your machine before performing these steps.
It worked for me. I had the same problem.
Below are two useful tutorials to walk you through the entire process.
PTVS 2.0 Beta: Creating a Django Website : A step by step guide
Django and MySQL on Azure with Python Tools 2.1 for Visual Studio

Categories

Resources