Django Visual Studio The environment '....' is not available - python

I had a virtual environment setup for Django 3 with visual studio. However at some point it seems that this previous environment has been damaged - and therefore is no longer working (nothing appears on git to have changed).
I therefore attempted to setup a new environment via the visual studio python environment options. I could setup a conda environment but it will not let me setup a python environment as "you will need to install a python interpreter...". However on the same page it states that the latest python 64 is installed.
It will not run with the conda environment that I have setup as it states "The environment '....' is not available."
I have tried creating a new solution with VS and this appears to work as intended. However it is not really an option to create a new solution as I will loose a lot of existing git commits along with this causing issues with existing servers.

Edit - Found my own answer to this question.
As new projects were allowing virtual environments to be created I figured it must be something to do with visual studio storing some reference to an old interpreter.
Therefore, Deleting the .vs folder inside my project allowed regeneration of the visual studio files and creation of a new virtual environment.

Related

Python not found

I'm working on a project in a python virtual environment, the project was started on a pc with python 3.8 installed and consequently python 3.8 was used in the virtual environment, or I had the need to continue the project on another pc, so I loaded all on GitHub, in the end I downloaded it to another PC with python 3.11 installed, the files are all there but when I try, inside the virtual environment, to open python by writing python or python3 in the terminal, it shows up this error: Python not found; Run with no arguments to install from the Microsoft Store or disable the link from Settings > Manage apps Run aliases. I then tried to see if it only showed up inside the virtual environment, but the same thing happens outside as well.
I tried to do various things among those suggested in other forums but they didn't work, the problem persists, I'm a bit lost, it's the first time this has happened to me.
Sorry to bother, maybe it's the simplest problem there is to solve but I don't know where to start
Trhanks
The problem is the different version of python on the two computers... the content of the pyvenv.cfg file must simply be changed which, when creating the virtual environment, is based on the installed version. Here you just need to change the path to reach the python.exe file installed on your computer and then change its version by inserting the correct one.

What makes for a well-constructed local environment?

I'm currently building an Azure Function. Currently I'm debugging the script and I've encountered a KeyError 'error in six.moves'. This similar problem suggests that it was a 'badly configured environment', and the solution was to "redo the virtual environment". What would count as a 'well-configured environment'? As far as my understanding goes, all that it has to be is that it meets the version requirements needed, and that no conflicts between dependencies should be present.
I will be attempting to redo my own virtual environment.
Please try the below steps if it helps to fix the issue:
What makes for a well-constructed local environment?
Make Sure you run the Azure Function (Python Stack) in virtual environment (.venv) in the Visual Studio Code.
Check all the required packages are available in the requirements.txt file.
If Virtual environment is not created while creating the Azure Functions Python in VS Code, you can create using the commands in terminal as given in thi s MS Doc.
Check the Azure Functions Core Tools version is the latest for the Python Version above 3.6
Check all the required packages are available by using the command pip list in the VS Code Terminal.
After that, start the function using the command func host start from the same project terminal in VS Code and check.

How to clear Visual Studio Code cache?

I am in anaconda dependency hell so I keep building and then deleting different environments and the Visual Studio Code cache seems confused about what environments are available, for example looking for an environment that has been deleted.
I uninstalled and reinstalled VSC (Windows Server 2012 - waiting for upgrade) but the issue persists.
Thanks for any thoughts.
When using Python in VS Code, it recognizes the available python executable file "python.exe", which we can view in the system variables:
In VS Code, it uses the python environment used last time by default, therefore, for unused python environments, you could select other available python environments in VS Code and ignore the deleted python environments. (F1, Python: Select Interpreter)
For more information about the python environment in VS Code, please refer to this document: Using Python environments in VS Code.
Reference: How do I add Python to the Windows PATH?

PTVS cant find Python interpreter?

I just copied my Flask project from one machine to another. I have same version of Python installed on both the machines. When I loaded the project in the new machine, it said my virtual environment is unavailable. So I initially tried to install it from requirements.txt file but it failed without any helpful error message.
So I deleted the virtual env in Visual Studio and tried to create another one. Now it complains that it cannot find any Python interpreters on my machine. I tried uninstall/reinstall Python but it didn't work. Also, the Python location is added in the PATH environment variable and all the modules in the requirements.txt file are downloaded from pip individually.
So the modules are installed, python is installed and the project is there but the virtual env won't setup because of the below reason. Any way that I can fix this ? This is PTVS15 and Python 3.6.1
Fixed it myself. I went ahead and added the environment manually by specifying the Python installation paths in the Add Environment tab. It took a while to detect the interpreter even in this way but it finally worked. I am now able to build my app.

Python Tools for Visual Studio & virtualenv - can use packages only present in deactivated env

I'm working on a Django project in VS 2015 Community with PTVS, which has been very useful for a free tool. I recently realized that I should be using virtual environments during development, and found out that Python 3 includes this feature by default, and PTVS 2.0+ supports it- cool!
I created a couple environments as an experiment, and in one I installed the celery[redis] bundle since I'm trying to figure out how to implement a background task. I was having trouble getting the basic celery tutorial task to work, so I decided to remove the environment from my Django project, deactivate it, and start over.
However, once I removed it via PTVS and ran deactivate from the command line inside the environment directory, I could still run celery commands from my top-level project directory. I've never installed celery globally- only to my test environment via the Python Environments menu in PTVS.
Why is this? Am I thinking of virtual environments as too similar to truly discrete environments such as containers? My impression from reading PTVS venv documentation is that if a package is present in a virtual environment which is then deactivated, I shouldn't be able to use it in other environments (or globally). I thought it might be an issue with my Windows PATH, but I didn't see anything related to Python or celery.
Apologies if this is a duplicate- it's been difficult to find questions on the PTVS implementation of venv rather than Python + virtualenv in general.

Categories