Miniforge / VScode - Python is not installed and virtualenv is not found

2024/10/12 9:06:31

I have been stuck on this issue for several days, so any help is greatly appreciated.

I recently had to move away from Anaconda (due to their change in the commercial policy) and decided to try Miniforge. It comes with Python 3.9, but since in most projects I need 3.7, I created a new venv with conda create --name StandardPython python=3.7.6.

Each time I open a python script I get the error message "Python is not installed":

enter image description here

even though it of course is, and I can even manually select the interpreter:

enter image description here

Moreover, the virtualenv I have created is not found in the list given by VScode:

enter image description here

I can select it manually with "Enter the interpeter path", but besides that being a long process to do each time I want to switch envs, it also does not fix the problem as at the next restart VScode still does not show the venv in the list, even though it is indicated as "current":

enter image description here

It's worth mentioning that I am not using workspaces at the moment, I am just opening the python file(s) directly. This worked perfectly with Anaconda and I could select all the venvs I created without problems from the list, so switching was a breeze. Somehow now it does not work anymore.

I have already tried:

  • Removing (conda env remove --name StandardPython) and recreating the environment
  • Setting the python:pythonpath in VScode to the base python ....\AppData\Local\miniforge3\python.exe
  • Setting the python:condapath to Miniforge's path ....\AppData\Local\miniforge3\Scripts\conda.exe
  • Uninstalling and reinstalling the Python plugin for VScode
  • Uninstalling and reinstalling VScode (also manually cleaning up all configs and plugin files
  • Uninstalling and reinstalling Miniforge
Answer

Ugh, a similar thing happened to me!

VS Code runs a series of commands to determine what interpreters it populates in that list when you attempt to set the python interpreter for your project. One of those commands it runs is conda env list. So then that is first thing you should check: run conda env list at your default terminal outside of VS Code.

Next, what terminal is that you are using? bash? zsh? Whatever terminal you are using outside of VS Code, (which you used for installing and configuring conda for instance) ensure that you set it to be the default terminal in VSCode. The root cause for this behavior is discussed here miniforge & vscode terminal needs to be set.

Finally restart VSCode and try to set the interpreter and see if your miniforge conda environments show up in the list. This worked for me as you can see in the screenshot.

enter image description here

Hope this helps!

https://en.xdnf.cn/q/69609.html

Related Q&A

How to merge pandas table by regex

I am wondering if there a fast way to merge two pandas tables by the regular expression in python .For example: table A col1 col2 1 apple_3dollars_5 2 apple_2dollar_4 1 o…

Scipy Optimize is only returning x0, only completing one iteration

I am using scipy optimize to get the minimum value on the following function: def randomForest_b(a,b,c,d,e):return abs(rf_diff.predict([[a,b,c,d,e]]))I eventually want to be able to get the optimal val…

Order of sess.run([op1, op2...]) in Tensorflow

I wonder whats the running order of the op list in sess.run(ops_list, ...). for example:for a typical classification scenario: _, loss = sess.run([train_op, loss_op]), if train_op run first,then the lo…

Django form validation: get errors in JSON format

I have this very simple Django formfrom django import formsclass RegistrationForm(forms.Form):Username = forms.CharField()Password = forms.CharField()I manage this manually and dont use the template en…

Django inheritance and polymorphism with proxy models

Im working on a Django project that I did not start and I am facing a problem of inheritance. I have a big model (simplified in the example) called MyModel that is supposed to represents different kind…

L suffix in long integer in Python 3.x

In Python 2.x there was a L suffix after long integer. As Python 3 treats all integers as long integer this has been removed. From Whats New In Python 3.0:The repr() of a long integer doesn’t include …

Custom Colormap

I want to plot a heatmap with a custom colormap similar to this one, although not exactly.Id like to have a colormap that goes like this. In the interval [-0.6, 0.6] the color is light grey. Above 0.6,…

Whats the point of @staticmethod in Python?

Ive developed this short test/example code, in order to understand better how static methods work in Python.class TestClass:def __init__(self, size):self.size = sizedef instance(self):print("regul…

logical or on list of pandas masks

I have a list of boolean masks obtained by applying different search criteria to a dataframe. Here is an example list containing 4 masks: mask_list = [mask1, mask2, mask3, mask4]I would like to find th…

How to view the implementation of pythons built-in functions in pycharm?

When I try to view the built-in function all() in PyCharm, I could just see "pass" in the function body. How to view the actual implementation so that I could know what exactly the built-in f…