Anaconda Prompt (py27) can't find where conda is located - python

I am a newbie for Python and I've found Spyder way too complicated to make it work. Since my default Spyder's Python version was 3+, I couldn't use the guide that I've found so I installed Spyder for Python 2.7 somehow. Now I need to install scikit-image but Anaconda prompt doesn't recognize "conda" commands.
So I've found that I should check where conda is located first but the prompt cannot even find where conda is so I wanted to ask it to people here.
The left one is for default, the right one is for py27.
enter image description here

Make sure to add Anaconda path to your environment variables.
Your steps will most likely be:
Windows: In your environment variables add C:\Users\[Your Username]\Anaconda3\Scripts to Path.
Ubuntu: edit your .bashrc and add export PATH=~/anaconda3/bin:$PATH
A shortcut to opening env. vars. in Windows: Open up your cmd and type:
rundll32 sysdm.cpl,EditEnvironmentVariables

(Posted on behalf of the question author).
Adding Anaconda3 and Anaconda3\Scripts paths to Path variable in the user variables has solved the problem.

Related

Cannot add conda environment to Pycharm - Conda executable path is empty even when it's not

I am pretty proficient in pycharm but it is the first time I stumble into this problem.
I created a conda environment
Finding the conda executable which for me is in /home/my_username/.miniconda3/envs/py39/bin/python
Adding it to pycharm results in:
I tried to search for this issue and error but the results didnt help.
I am using fedora 36 if it is relevant.
Edit: The output of which conda is:
/home/my_username/.miniconda3/condabin/conda
Then trying to add it as the interpreter as suggested in Pycharm: Conda executable path is empty:
Got it, thank you!
In the path you should define a path to the python.exe in the conda environment directory.
Here is an example:
I ended up re-installing the OS and now it works, I would not call it a solution but it is what it is - I couldnt waste more time on this as I have work to do.
You need to first tell PyCharm where conda executable is. This is not so obvious how, as there is no input field for that when adding existing conda environments. IMO it's a UX flaw in PyCharm.
I found this input field only available when creating a NEW conda environment from within a PyCharm. Enter a 'Conda executable' there. In your case: /home/????/.miniconda3/bin/conda
Then I also created a new dummy conda environment so the path is stored and PyCharm is happy. Afterwards, you shouldn't get that "Conda executable path is empty" anymore when adding new conda interpreter.
As the error mentions either you do not have a Conda installed on your system or the path is not recognized by the IDE. Creating a new project, double check if the bar conda executable: is correctly filled by the directory to the folder Conda is installed on your system.
Normally your IDE fill the conda executable automatically, if this is not the case and manually filling the empty bar did not help, I would recommend to delete and reinstall your conda.
Good Luck

Basic python commands no longer recognised in VS Code [duplicate]

I installed Anaconda3 4.4.0 (32 bit) on my Windows 7 Professional machine and imported NumPy and Pandas on Jupyter notebook so I assume Python was installed correctly. But when I type conda list and conda --version in command prompt, it says conda is not recognized as internal or external command.
I have set environment variable for Anaconda3; Variable Name: Path, Variable Value: C:\Users\dipanwita.neogy\Anaconda3
How do I make it work?
I was faced with the same issue in windows 10, Updating the environment variable following steps, it's working fine.
I know It is a lengthy answer for the simple environment setups, I thought it's may be useful for the new window 10 users.
1) Open Anaconda Prompt:
2) Check Conda Installed Location.
where conda
3) Open Advanced System Settings
4) Click on Environment Variables
5) Edit Path
6) Add New Path
C:\Users\RajaRama\Anaconda3\Scripts
C:\Users\RajaRama\Anaconda3
C:\Users\RajaRama\Anaconda3\Library\bin
7) Open Command Prompt and Check Versions
8) After 7th step type
conda install anaconda-navigator in cmd then press y
Although you were offered a good solution by others I think it is helpful to point out what is really happening. As per the Anaconda 4.4 changelog, https://docs.anaconda.com/anaconda/reference/release-notes/#what-s-new-in-anaconda-4-4:
On Windows, the PATH environment variable is no longer changed by default, as this can cause trouble with other software. The recommended approach is to instead use Anaconda Navigator or the Anaconda Command Prompt (located in the Start Menu under “Anaconda”) when you wish to use Anaconda software.
(Note: recent Win 10 does not assume you have privileges to install or update. If the command fails, right-click on the Anaconda Command Prompt, choose "More", chose "Run as administrator")
This is a change from previous installations. It is suggested to use Navigator or the Anaconda Prompt although you can always add it to your PATH as well. During the install the box to add Anaconda to the PATH is now unchecked but you can select it.
I found the solution.
Variable value should be C:\Users\dipanwita.neogy\Anaconda3\Scripts
When you install anaconda on windows now, it doesn't automatically add Python or Conda to your path.
While during the installation process you can check this box, you can also add python and/or python to your path manually (as you can see below the image)
If you don’t know where your conda and/or python is, you type the following commands into your anaconda prompt
where python
where conda
Next, you can add Python and Conda to your path by using the setx command in your command prompt (replace C:\Users\mgalarnyk\Anaconda2 with the results you got when running where python and where conda).
SETX PATH "%PATH%;C:\Users\mgalarnyk\Anaconda2\Scripts;C:\Users\mgalarnyk\Anaconda2"
Next close that command prompt and open a new one. Congrats you can now use conda and python
Source: https://medium.com/#GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444
Just to be clear, you need to go to the controlpanel\System\Advanced system settings\Environment Variables\Path,
then hit edit and add:
C:Users\user.user\Anaconda3\Scripts
to the end and restart the cmd line
In addition to adding C:\Users\yourusername\Anaconda3 and C:\Users\yourusername\Anaconda3\Scripts, as recommended by Raja (above), also add C:\Users\yourusername\Anaconda3\Library\bin to your path variable. This will prevent an SSL error that is bound to happen if you're performing this on a fresh install of Anaconda.
If you have a newer version of the Anaconda Navigator, open the Anaconda Prompt program that came in the install. Type all the usual conda update/conda install commands there.
I think the answers above explain this, but I could have used a very simple instruction like this. Perhaps it will help others.
Go To anaconda prompt(type "anaconda" in search box in your laptop). type following commands
where conda
add that location to your environment path variables. Close the cmd and open it again
This problem arose for me when I installed Anaconda multiple times. I was careful to do an uninstall but there are some things that the uninstall process doesn't undo.
In my case, I needed to remove a file Microsoft.PowerShell_profile.ps1 from ~\Documents\WindowsPowerShell\. I identified that this file was the culprit by opening it in a text editor. I saw that it referenced the old installation location C:\Anaconda3\.
For conda --version greater than 4.6, from the base of your Anaconda promt, run
conda update conda
conda init
This will update your conda root environment and setup the stuff you need to run it on both cwd and powershell.
After this, you can start any terminal and it will be conda ready.
If you don't want to add Anaconda to env. path and you are using Windows try this:
Open cmd;
Type path to your folder instalation. It's something like:
C:\Users\your_home folder\Anaconda3\Scripts
Test Anaconda, for exemple type conda --version.
Update Anaconda: conda update conda or conda update --all or conda update anaconda.
Update Spyder:
conda update qt pyqt
conda update spyder
I have Windows 10 64 bit, this worked for me,
This solution can work for both (Anaconda/MiniConda) distributions.
First of all try to uninstall anaconda/miniconda which is causing problem.
After that delete '.anaconda' and '.conda' folders from 'C:\Users\'
If you have any antivirus software installed then try to exclude all the folders,subfolders inside 'C:\ProgramData\Anaconda3\' from
Behaviour detection.
Virus detection.
DNA scan.
Suspicious files scan.
Any other virus protection mode.
*(Note: 'C:\ProgramData\Anaconda3' this folder is default installation folder, you can change it just replace your excluded path at installation destination prompt while installing Anaconda)*
Now install Anaconda with admin privileges.
Set the installation path as 'C:\ProgramData\Anaconda3' or you can specify your custom path just remember it should not contain any white space and it should be excluded from virus detection.
At Advanced Installation Options you can check "Add Anaconda to my PATH environment variable(optional)" and "Register Anaconda as my default Python 3.6"
Install it with further default settings. Click on finish after done.
Restart your computer.
Now open Command prompt or Anaconda prompt and check installation using following command
conda list
If you get any package list then the anaconda/miniconda is successfully installed.
I have just launched anaconda-navigator and run the conda commands from there.
For those who didn't check "Add Anaconda to my PATH environment variable". In Windows 10 it looks like that:
5 paths:
C:\Users\shtosh\anaconda3
C:\Users\shtosh\anaconda3\Library\mingw-w64\bin
C:\Users\shtosh\anaconda3\Library\usr\bin
C:\Users\shtosh\anaconda3\Library\bin
C:\Users\shtosh\anaconda3\Scripts
if you use chocolatey, conda is in C:\tools\Anaconda3\Scripts
I had this problem in windows. Most of the answers are not as recommended by anaconda, you should not add the path to the environment variables as it can break other things. Instead you should use anaconda prompt as mentioned in the top answer.
However, this may also break. In this case right click on the shortcut, go to shortcut tab, and the target value should read something like:
%windir%\System32\cmd.exe "/K" C:\Users\myUser\Anaconda3\Scripts\activate.bat C:\Users\myUser\Anaconda3

How to change default conda environment in Anaconda Prompt?

I have Anaconda installed in my machine with two environments one is base(default) and other is vision.
Whenever I open Anaconda Prompt, it opens in the base environment and I have to change the environment manually using
$ activate vision
So I'm looking for a way to open Anaconda Prompt in my vision environment by default.
Is it possible to do so?
OS: Windows10
Anaconda: 4.5.11
P.S: I have already gone through the similar question asked here. Accepted answer doesn't provide a solution here as my both python versions are 3.6.
Instead of messing with the path and stuff in my .bashrc file, I simply appended the line:
conda activate sdesign
My environment name is sdesign. So it simply activates the environment every time I open a new terminal. Hope that helps.
If you want to start anaconda-navigator with a particular environment [e.g MyEnv ] then For Linux OS I know a method. Maybe, it will be beneficial for someone. So, I'm sharing it.
First, completely close anaconda-navigator and the edit the file
Open ~/.anaconda/navigator/anaconda-navigator.ini.
change
default_env = '/home/user/anaconda3'
to
default_env = '/home/user/anaconda3/envs/MyEnv'
Note: Here /home/{user will be different for everyone}/anaconda ... like that.
You can also edit another options like
dataspell_path =
pycharm_ce_path =
pycharm_pro_path =
vscode_path = /usr/share/code
and so on.
For windows there will be a file maybe in
C:/User/AppData/local/anacond/anaconda-navigator.ini like that. Edit that like the solution. Surely that will also work.

Activating Anaconda Environment in VsCode

I have Anaconda working on my system and VsCode working, but how do I get VsCode to activate a specific environment when running my python script?
Simply use
shift + cmd + P
Search Select Interpreter
Select it and it will show you the list of your virtual environment created via conda and other python versions
select the environment and you are ready to go.
Quoting the 'Select and activate an environment' docs
Selecting an interpreter from the list adds an entry for python.pythonPath with
the path to the interpreter inside your Workspace Settings.
If Anaconda is your default Python install then it just works if you install the Microsoft Python extension.
The following should work regardless of Python editor or if you need to point to a specific install:
In settings.json edit python.path with something like
"python.pythonPath": "C:\\Anaconda3\\envs\\py34\\python.exe"
Instructions to edit settings.json
Setting python.pythonPath in VSCode's settings.json file doesn't work for me, but another method does. According to the Anaconda documentation at Microsoft Visual Studio Code (VS Code):
When you launch VS Code from Navigator, VS Code is configured to use the Python interpreter in the currently selected environment.
The best option I found is to set the python.venvPath parameter in vscode settings to your anaconda envs folder.
"python.venvPath": "/Users/[...]/Anaconda3/envs"
Then if you bring up the command palette (ctl + shift + P on windows/linux, cmd + shift + P on mac) and type Python: Select Workspace Interpreter all your envs will show up and you can select which env to use.
The python extension will also need to be installed for the Select Workspace Interpreter option.
Note: The Select Workspace Interpreter takes around 10 seconds to come up on my computer using the current version of VSCode.
Although approved answer is correct, I want to show a bit different approach (based on this answer).
Vscode can automatically choose correct anaconda environment if you start vscode from it. Just add to user/workspace settings:
{
"python.pythonPath": "C:/<proper anaconda path>/Anaconda3/envs/${env:CONDA_DEFAULT_ENV}/python"
}
It works on Windows, macOS and probably Unix. Further read on variable substitution in vscode: here.
Unfortunately, this does not work on macOS. Despite the fact that I have export CONDA_DEFAULT_ENV='$HOME/anaconda3/envs/dev' in my .zshrc and "python.pythonPath": "${env.CONDA_DEFAULT_ENV}/bin/python",
in my VSCode prefs, the built-in terminal does not use that environment's Python, even if I have started VSCode from the command line where that variable is set.
Just launch the VS Code from the Anaconda Navigator. It works for me.
Find a note here: https://code.visualstudio.com/docs/python/environments#_conda-environments
As noted earlier, the Python extension automatically detects existing
conda environments provided that the environment contains a Python
interpreter. For example, the following command creates a conda
environment with the Python 3.4 interpreter and several libraries,
which VS Code then shows in the list of available interpreters:
conda create -n env-01 python=3.4 scipy=0.15.0 astroid babel
In contrast, if you fail to specify an interpreter, as with conda create
--name env-00, the environment won't appear in the list.
If you need an independent environment for your project:
Install your environment to your project folder using the --prefix option:
conda create --prefix C:\your\workspace\root\awesomeEnv\ python=3
In VSCode launch.json configuration set your "pythonPath" to:
"pythonPath":"${workspaceRoot}/awesomeEnv/python.exe"
Python Path is now deprecated and now you should set Conda Path instead. This way you can pick different environements on the fly.
Click ctrl + , then search for Conda Path and add absolute path to script, e.g.:
C:\Users\{myUser}\miniconda3\Scripts\conda.exe
Pick specific environment for each project in bottom left corner or through Command Pallete (ctrl + Shift + P -> search Python: Select Interpreter)
The simplest way to do it -
First open up terminal or command line and navigate to the project directory where you created the virtual environment.
Then activate the virtual environment with the command
conda activate venv_name
Once activated, in terminal type -
code .
This will open the vscode with the activated virtual environment. Look at the bottom of the pic. The dot after code . tells terminal to open the current directory in vscode.
I found out that if we do not specify which python version we want the environment which is created is completely empty. Thus, to resolve this issue what I did is that I gave the python version as well. i.e
conda create --name env_name python=3.6
so what it does now is that it installs python 3.6 and now we can select the interpreter. For that follow the below-mentioned steps:
Firstly, open the command palette using Ctrl + Shift + P
Secondly, Select Python: select Interpreter
Now, Select Enter interpreter path
We have to add the path where the env is, the default location will be
C:\Users\YourUserName\Anaconda3\envs\env_name
Finally, you have successfully activated your environment.
It might now be the best way but it worked for me. Let me know if there is any issue.
I found a hacky solution replace your environment variable for the original python file so instead it can just call from the python.exe from your anaconda folder, so when you reference python it will reference anaconda's python.
So your only python path in env var should be like:
"C:\Anaconda3\envs\py34\", or wherever the python executable lives
If you need more details I don't mind explaining. :)
As I was not able to solve my problem by suggested ways, I will share how I fixed it.
First of all, even if I was able to activate an environment, the corresponding environment folder was not present in C:\ProgramData\Anaconda3\envs directory.
So I created a new anaconda environment using Anaconda prompt,
a new folder named same as your given environment name will be created in the envs folder.
Next, I activated that environment in Anaconda prompt.
Installed python with conda install python command.
Then on anaconda navigator, selected the newly created environment in the 'Applications on' menu.
Launched vscode through Anaconda navigator.
Now as suggested by other answers, in vscode, opened command palette with Ctrl + Shift + P keyboard shortcut.
Searched and selected Python: Select Interpreter
If the interpreter with newly created environment isn't listed out there, select Enter Interpreter Path and choose the newly created python.exe which is located similar to C:\ProgramData\Anaconda3\envs\<your-new-env>\ .
So the total path will look like C:\ProgramData\Anaconda3\envs\<your-nev-env>\python.exe
Next time onwards the interpreter will be automatically listed among other interpreters.
Now you might see your selected conda environment at bottom left side in vscode.
"python.pythonPath" is deprecated, quote from vscode:
The "python.pythonPath" setting in your settings.json is no longer
used by the Python extension. If you want, you can use a new setting
called "python.defaultInterpreterPath" instead. Keep in mind that you
need to change the value of this setting manually as the Python
extension doesn’t modify it when you change interpreters. Learn more.
Thus, IF you want to assign the path manually (not reccommended, as explained above), open the "settings.json" of your workspace or the default one and use
{
"python.defaultInterpreterPath": "C:\\Users\\MYUSER\\anaconda3\\envs\\testenv\\python.exe"
}

Why Anaconda does not recognize conda command?

I installed the latest version of Anaconda.
Now I want to install OpenCV within it. When I type:
conda install -c https://conda.binstar.org/anaconda opencv
I get this message error: "conda is not recognized as internal command ..." (sorry, I try to translate from French because my OS is in French)
The problem is that conda comes with Anaconda, so I wonder why lauching Anaconda and type the above command does not work ?
For Windows
Go to Control Panel\System and Security\System\Advanced System Settings then look for Environment Variables.
Your user variables should contain Path=Path\to\Anaconda3\Scripts.
You need to figure where your Anaconda3 folder is (i.e. the path to this folder) . Mine was in C:\Users.
For Linux
You need to add conda to PATH. To do so, type:
export PATH=/path/to/anaconda3/bin:$PATH.
Same thing, you need to figure the path to anaconda3 folder (Usually, the path is stored in $HOME)
If you don't want to do this everytime you start a session, you can also add conda to PATH in your .bashrc file:
echo 'export PATH=/path/to/anaconda3/bin:$PATH' >> ~/.bashrc
I had a similar problem. I searched conda.exe and I found it on Scripts folder. So, In Anaconda3 you need to add two variables to PATH. The first is Anaconda_folder_path and the second is Anaconda_folder_path\Scripts
When you install anaconda on windows now, it doesn't automatically add Python or Conda to your path so you have to add it yourself.
If you don’t know where your conda and/or python is, you type the following commands into your anaconda prompt
Next, you can add Python and Conda to your path by using the setx command in your command prompt.
Next close that command prompt and open a new one. Congrats you can now use conda and python
Source: https://medium.com/#GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444
I had a similar problem and I did something like the below mentioned steps with my Path environment variable to fix the problem
Located where my Anaconda3 was installed. I run Windows 7. Mine is located at C:\ProgramData\Anaconda3.
Open Control Panel - System - Advanced System Settings, under Advanced tab click on Environment Variables.
Under System Variables, located "Path" add the following: C:\ProgramData\Anaconda3\Scripts;C:\ProgramData\Anaconda3\;
Save and open new terminal.
type in "conda". It worked for me.
Hope these steps help
You probably need to update your PATH variable to include where you have installed Anaconda.
See https://github.com/ContinuumIO/anaconda-issues/issues/41 for a similar issue.
I suspect you forget to export PATH, anaconda/bin must be added in your $PATH. (Linux, OSX common problem). On Windows make sure you run install and commands as administrator.
Same problem with Anaconda running on Ubuntu 15.10. I closed the terminal and opened a new window and it worked fine.
Faced the same problem running on Windows 10 and using the Windows cmd.
Solved it by running the following command in the Anaconda Prompt which comes with Anaconda3 (as administrator):
conda install -c menpo opencv3=3.1.0
Command found on the official website: https://anaconda.org/menpo/opencv3
Try setting the file path using (for anaconda3)...
export PATH=~/anaconda3/bin:$PATH
Then check whether it worked with...
conda --version
This worked for me when 'conda' was returning 'command not found'.
Try restarting the terminal, I had the same issue, worked after restarting the terminal.
If this problem persists, you may want to check all path values in the PATH variable (under Control Panel\System and Security\System\Advanced System Settings). It might be that some other path is invalid or contains an illegal character.
Today, I had the same problem and found a double quote in a different path value in the PATH variable. All paths after that (including a fresly installed conda) were not usable. Removing the double quote solved the problem.
In Windows 10, I went to the folder where Anaconda is stored. In my case it is in \Anaconda3 folder as a shortcut to open a command prompt window, called "Anaconda Prompt". Open that and execute the command there.
Got same issue and it turns out that besides setting PATH variable, I also should not close some cmd window poped up during installation. Re-installation would work
It's not recommended to add conda.exe path directly into the System Environment Variables at stated by anaconda installer :
For Windows Users, Open Conda Prompt Shortcut and change the Target into the Correct Address :
As other users said, the best way for Windows users is to set the global environment variable.
I install the Miniconda3 for MXNet.
Before I do something, only Anaconda Prompt works for conda.
After setting the global environment variable, The CMD and Git Bash work.
But in some IDEs like RStudio, the nested Git Bash doesn't work.
After restarting my computer, the Git Bash in the RStudio works for conda.
I hope these tests helps for you.
On Windows 11 x64, default is
"C:\ProgramData\Anaconda3\Scripts\conda.exe"
CMD, run, systempropertiesadvanced , add to PATH variable.

Categories