Why my VSCode's interpreter is not working in Mac? - python

I have VSCode and I am trying to set up a virtual environment. First, I created all the venv properly. When I run in the Terminal is working and activated. However, it is not showing up in the VSCode. Make the matter worse, I can not change my interpreter at all. At first, I had python 2.7 and I could not change into python3 even though everything is set up properly. I fixed that problem with this setting "code-runner.executorMap.python": "python3 -u". And how I cannot change to another interpreter without the delete the setting. I am not sure what to do. Please help.
Thanks

Others have reported setting up virtual environments using VSCode. I suggest you set up your virtual environment using the terminal and activating the environment before starting VSCode. If you are using Anaconda Python this source will instruct you on setting up a virtual environment. For non-anaconda python, there are many pages for doing the same
To change the interpreter in VSCode, go to the View menu and select the Command Palette. When the command palette opens type python in the text box. This will cause commands with python in its name to be displayed. The first command (on my machine) is Python: Select interpreter. Select this and hit return. You will be given a list of python interpreters to choose from.

Related

How can i add Anaconda Prompt to VScode terminal?

i'm trying to add anaconda prompt to vscode terminal.
i googled it, but i found that it's not possible method cuz
terminal.integrated.shell.windows
terminal.integrated.shellArgs.windows
is now unavailable on settings.
is there any way to solve this?
I'm sorry to tell you that it can't be realized at present.The Python extension automatically detects existing conda environments provided that the environment contains a Python interpreter. Although the Python extension for VS Code doesn't currently have direct integration with conda environment.yml files, VS Code itself is a great YAML editor.
The most I could think of is setting Conda as your interpreter (in the Command Palette type in Python Interpreter, select it, and click on the one that says "conda"). That should allow you to run your code in the conda enviornment.

VSCode not selecting the correct python interpreter

I have a script that I need to run using a very specific python interpreter in my hard drive.
I am using vscode as the IDE and trying to select the python interpreter using the command palette.
However, since the concerned interpreter is not present, I manually search it.
However, even after that, it doesn't work as typing python in the terminal then opens the windows store for installing a python IDE. I also tried adding the interpreter's path to the environment variables but the problem still persists.
How do I solve this issue.
Thank You for the help.
The Python version you selected on VS Code only effects the editor. Right click to any file on the sidebar and select Open in Integrated Terminal. If your selected Python version is created with virtualenv it will activated and your python command works.
If not worked and you want a global Python version, you need to add Python path to your system variables to work python command. Check this:
https://geek-university.com/python/add-python-to-the-windows-path/
Btw I don't think your python.exe in FreeCad/bin directory is proper Python version
At the bottom left you can select the Python interpreter.
Here it shows you on -how to do that: Python Interpreter
Reason:
Your system environment path contains this: %USERPROFILE%\AppData\Local\Microsoft\WindowsApps.
Solution:
Open Window Search(Win) to find Manage app execution aliases. To turn off App Installer of python3 like this:
You can refer to this answer for more information.

Python Module Can Not be Found Even Though It Is Installed

I used python and pandas so many times in VS Code but It causes a problem right know : problem
The terminal looks like this : terminal and I checked if matplotlib is installed or not but seems like it is installed matplotlib check. I don't know why this is happening but It was working until now.
The reason is that the python environment you are currently using in VS Code is different from the python environment used by the VS Code terminal.
Solution: Please close the currently used VS Code terminal (click the icon "Kill Terminal"), then select the python environment that has installed the required module at the bottom left of VS Code, and then use the shortcut key Ctrl+Shift+` to open the new VS Code terminal.
In addition, I noticed that you are using a powershell terminal. If you are using a virtual environment or conda environment, we need to activate this environment in the terminal (Usually it will automatically activate when a new terminal is opened.):
Check module:
Run:
Reference: Using Python environments in VS Code.

How to have conda commands match behaviour in Vscode's integrated terminal and normal terminal?

I was put off because conda info --envs does NOT display the same thing that my terminal does. Terminal:
(automl) brandBrandoParetoopareto~/anaconda3/envs $ conda info --envs
# conda environments:
#
base /Users/brandBrandoParetoopareto/anaconda3
automl * /Users/brandBrandoParetoopareto/anaconda3/envs/automl
coqgym /Users/brandBrandoParetoopareto/anaconda3/envs/coqgym
vscode integrated terminal outpute:
(automl) brandBrandoParetoopareto~/ultimate-utils $ conda info --envs
# conda environments:
#
/Users/brandBrandoParetoopareto/anaconda3
base * /Users/brandBrandoParetoopareto/anaconda3/envs/automl
/Users/brandBrandoParetoopareto/anaconda3/envs/coqgym
it is really strange because it seems to be using the right env which I would have not know because in the debugger window it does not show (automl) but says (base) but points to the right env (In fact the previous command output if you read it carefully says it's using (automl) but then it's actually using base BUT it seems to be pointing to the right environment!?!? But wrong names).
This seems like weird behavior does anyone know how to fix this or if it's causing other unexpected issues?
Perhaps this should be posted in vscode issues but I couldn't figure out which one since there is a vscode and a vscode-python one too.
Related issue:
I initially saw this issue Conda and Visual Studio Code debugging because I thought since it was pointing at base (or at least displaying wrong names) that it didn't recognize or know where my conda path was so that question seemed useful but ended up not fixing the naming issues.
Initially I also thought that it might have been related to a conda init issue I had exactly 30 days ago but it wasn't related unfortuantely Why is conda init updating my .bash_profile incorrectly?
Per comment request to check inheritEnv (to get to it go to settings then in search bar type inheritEnv):
the box is unchecked which I assume means "terminal.integrated.inheritEnv" is set to false
The weird thing I am seeing now is that:
the bottom conda right option to select environments, the environment I want to use does NOT appear. Even when I paste the path to it's option it does not work.
When I start a new terminal, somehow it decides to activate base by it's own eventhough my zsh already starts using the correct environment. Why is that? But even when I do zsh to start a new prompt, the bottom left does not seem to point to the right conda env.
My recommendation would be to simply set VS Code to use the shell you are using normally:
How to change the integrated terminal in visual studio code or VSCode
Have you set the python environment in VScode? If not explicitly it picks the first python it can find according to it's python search algorithm.
The Status Bar always shows the current interpreter.
To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
This interpreter will be saved in the workspace settings:
Selecting an interpreter from the list adds an entry for python.pythonPath with the path to the interpreter inside your Workspace Settings. Because the path is part of the workspace settings, the same environment should already be selected whenever you open that workspace. If you'd like to set up a default interpreter for your applications, you can instead add an entry for python.pythonPath manually inside your User Settings. To do so, open the Command Palette (Ctrl+Shift+P) and enter Preferences: Open User Settings. Then set python.pythonPath, which is in the Python extension section of User Settings, with the appropriate interpreter.
Caveats:
Conda environments can't be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the shell, see Integrated terminal - Configuration.
Conda environment in your project will be used, but only if the conda environment contains the python interpreter, by setting python= when creating the conda environment:
conda create -n env-01 python=3.4
For further details check the python environments section of the VSCode documentation.
https://code.visualstudio.com/docs/python/environments

Automatically activating Python venv when using PowerShell in PyCharm

When using cmd.exe as the terminal application in PyCharm, the Python venv for the project gets automatically activated, so, I don't need to run venv\Scripts\activate. But when using PowerShell this doesn't happen. Is it possible to make this happen?
This is the option that has to be ticked to activate the Python virtual environment:
which is ticked by default and was ticket in my case. The reason why it wasn't working (and failing silently) was because I move the parent directory to a different location on my hard drive and that seemed to break the venv. Deleting it and re-creating it fixed the problem.

Categories