Poetry installed but `poetry: command not found` - python

I've had a million and one issues with Poetry recently.
I got it fully installed and working yesterday, but after a restart of my machine I'm back to having issues with it ;(
Is there anyway to have Poetry consistently recognised in my Terminal, even after reboot?
System Specs:
Windows 10,
Visual Studio Code,
Bash - WSL Ubuntu CLI,
Python 3.8.
Terminal:
me#PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry run python3 cli.py
poetry: command not found
me#PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
Retrieving Poetry metadata
This installer is deprecated. Poetry versions installed using this script will not be able to use 'self update' command to upgrade to 1.2.0a1 or later.
Latest version already installed.
me#PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry run python3 cli.py
poetry: command not found
me#PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$
Please let me know if there is anything else I can add to post to help further clarify.

Since this is the top StackOverflow result for "poetry command not found"...
For Mac users, create a .zshrc file in your home folder with the following:
export PATH="$HOME/.local/bin:$PATH"

When I run this, after shutdown of bash Terminal:
export PATH="$HOME/.poetry/bin:$PATH"
poetry command is then recognised.
However, this isn't enough alone; as every time I shutdown the terminal I need to run the export.
Possibly needs to be saved in a file.

To follow-up on #StressedBoi69420's answer, could you add the line he suggested, i.e.
export PATH="$HOME/.poetry/bin:$PATH"
to your .bashrc?
As per this other Stack Overflow post What is the default install path for poetry and #arshbot's answer, I have added the line
export PATH=$PATH:$HOME/.poetry/bin to my .zshrc and it seems to be working.

I updated poetry to v1.2.2 (Nov 2022), but had issues with the path being set properly. This was the path definition I found:
Windows 10:
C:\User\<myUserName>\AppData\Roaming\pypoetry\venv\Scripts
Add it temporarily to your path with:
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\pypoetry\venv\Scripts
Or set this in your usual Windows Environment setup

Just to add some beginner level context around Julien's excellent answer, to find and edit your .zshrc file, you need to use your default editor (in this case i am using VSCode) and run:
>> code ~/.zshrc
...and, crucially, restart the terminal.
More details and the source of this info here: https://superuser.com/questions/886132/where-is-the-zshrc-file-on-mac

After installation - To add poetry to your shell script in Mac add following commands in terminal
open ~/.zshrc
If zshrc file is not created previously then create it using the following commands -
The .zshrc file is not present by default in macOS Catalina, we need to create it.
Steps for creation:
Open Terminal
Type touch ~/.zshrc to create the respective file. (touch command will create the .zshrc in your current directory but it will be hidden)
Hit Return
To open the zshrc file
Open Terminal > and type: open ~/.zshrc
In the .zshrc file add the line -
export PATH="$HOME/.local/bin:{$PATH}”
Once you have added the above command to the .zshrc file, go back to the terminal and refresh the terminal by -
source ~/.zshrc
Then execute the following in terminal
poetry --version
If you get the version name then you are ready to use!
Additionally you can refer the https://python-poetry.org/docs/#installation for further information during installation in other operating system environments.

Generally the path of Poetry should be added to the ENV variable PATH.
1. use which find where is poetry installed just after you installed poetry.
which poetry
# $HOME/.local/bin/poetry # if installed with Brew
# maybe elsewhere: "$HOME/.poetry/bin:$PATH"
In fact, it reminds users to add the path to the shell configuration file in the output of the Poetry installation.
Installing Poetry (1.2.2): Done
Poetry (1.2.2) is installed now. Great!
To get started you need Poetry's bin directory
(/home/shell/.local/bin) in your PATH environment variable.
Add export PATH="/home/shell/.local/bin:$PATH" to your shell
configuration file.
Alternatively, you can call Poetry explicitly with
/home/shell/.local/bin/poetry.
2. find what kind of shell you are using:
echo $SHELL
# /usr/bin/zsh # many people use zsh or oh-my-zsh
  # For zsh, put stuff in ~/.zshrc, which is always executed.
  # For bash, put stuff in ~/.bashrc, and make ~/.bash_profile source it.
3. add the Poetry executable path to $PATH and add it to a shell startup configuration file to init it every time you start with that shell:
export SHELL_RCFILE="~/.zshrc"
echo "export POETRY_PATH=$HOME/.local/bin/ && export PATH="$POETRY_PATH:$PATH" >> $SHELL_RCFILE
Reference: zsh, bash startup files loading

After installation of Poetry you gotin output command line the tips:
Add export PATH="/Users/USERNAME/.local/bin:$PATH" to your shell configuration file.
Alternatively, you can call Poetry explicitly with /Users/USERNAME/.local/bin/poetry.
ps: I've installed it in MacOS using curl.

Related

Stuck when setting up to use anaconda with VS Code and Integrated Git terminal

I want to learn Data Science and so have used some really popular Python modules likes Pandas, Matplotlib, Numpy, etc. So I clean installed Anaconda and am now using it as my default Python interpreter and also using Conda for installing packages and making virtual environments. I use VS Code as my daily text editor. But I have run into some issues when using the integrated Git terminal in VS Code with the Anaconda Python interpreter.
There are a couple of issues that I am facing. One of the first issues that I see is when I am using CMD to run Python. If I type and enter python in cmd, the Python interpreter provided by anaconda comes up. But I also get a warning:
Warning:
This Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load. To activate this environment please see https://conda.io/activation
I didn't expect to get this output. Anyway, there's another problem in VS code. But first I would like to mention that I have checked "Add to PATH" when installing Anaconda so no issues there. Now, when I open a new Terminal in VS Code, automatically C:/Users/User/Anaconda3/Scripts/activate is run and then conda activate base is run. But when conda activate base is run, automatically, as mentioned, I get a CommandNotFoundError. It states Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'
And then I am told to initialize my shell, so I did conda init bash but still no luck. And this brings me to talk about .bash_profile. I think it has to do something with this bash profile. Anyway, this is what is in my bash profile
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/C/Users/User/Anaconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
# <<< conda initialize <<<
Just a summary of the problem:
Unexpected warning in CMD when running Anaconda Python interpreter
Automatically run Anaconda Scripts and conda activate base when opening new Terminal in VS Code
Conda init bash not helping
P.S I have tried using conda activate [env_name] in CMD and also in Git Bash and they work without any issues. In other words, Anaconda and Conda work perfectly outside of VS Code terminal.
I have figured out the answer myself and would like to share it here. First of all at the time of writing the question I was using Git Bash as my Terminal in VS Code (am still using it). So the issue was that when I ran the command conda init bash in Git Bash or the VS Code Terminal, Conda just basically put the command used for activating Conda environments in the .bash_profile since it is sourced during logging into Bash. But the integrated Terminal in VS Code is a subshell of a Git Bash session. That is why .bash_profile is NOT sourced in VS Code since .bash_profile is only sourced during the main Bash session. The .bashrc file is the file that is sourced when creating a Terminal session in VS Code. So what you actually need to do is take the code that is put into .bash_profile by conda init bash and paste it into your .bashrc file and make the .bash_profile source that .bashrc file automatically.
So, to sum up, using conda init bash will put the conda command in the .bash_profile and it is usually sourced by Git Bash, but VS Code Git Bash terminal will use .bashrc.
So you can just cut and paste the code from .bash_profile to .bashrc (as already mentioned) or if you want, just simply follow this: put this code in your .bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
And in your .bashrc, put this code:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('{path_to_your_conda.exe}' 'shell.bash' 'hook')"
# <<< conda initialize <<<
# You can get conda.exe path by using `which conda` in Git Bash
Now, when you open up a Git Bash session in VS Code Terminal, you can use conda activate env_name to activate any environments you have.
Everything is now supposed to work as expected in VS Code terminal but I would like to further elaborate about something. If you want, you can skip the conda init bash process (NOT recommended, just read on for additional knowledge but please follow the above steps only). This is a feature that was introduced in conda 4.4.0. Till then the way of activating conda environments was by using source activate but that command was NOT cross-platform, meaning that the command could not be used in OSes like Windows.
So they made this change by introducing commands like: conda activate env_name so that conda environments become much easier to use despite the OS platform.
conda activate also has other advantages. This is directly from their release docs:
conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4, conda activate and conda deactivate are now the preferred commands for activating and deactivating environments. You'll find they are much more snappy than the source activate and source deactivate commands from previous conda versions. The conda activate command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like Python virtualenv's activate script.
I used this question as a reference. Check it out to learn more.
Having said that, using source activate env_name will still work if you are using Git Bash, even in VS Code Git Bash terminal. source activate env_name requires no prior set up or config. But it is highly recommended that you only use conda init to set everything up and then use conda activate env_name.
[NOTE]: Locating and modifying the said .bashrc and .bash_profile on Windows is usually not as simple as it is on Linux. But can be done fairly easily like this:
It goes without saying but, you should have Git Bash installed. Having Git Bash installed should, as far as I know, automatically create .bashrc or .bash_profile or maybe both. These files are called "dotfiles" (since they start with a dot) and these are by default hidden on most OSes and definitely on Windows. If they were auto-created by Git Bash on your system, it is most likely that they are placed in your home directory. Home directory on Windows is C:\Users\<you>\. With that said, follow this:
Open Git Bash and go to your home directory with: cd. Just type this and you will be in your home directory
Enter this command: ls -a and you will see all your files, even hidden ones. Look for .bash_profile and .bashrc. Both should be present. If they are, you are ready to follow the above instructions. But if one is not there or if both are missing create them using: touch .bashrc && touch .bash_profile. You should now see these files when you again type: ls -a
That's it. Now that you have your .bashrc and .bash_profile, you can follow the above instructions. Also, to access these two files quicker, open them like this with VS Code: code ~/.bashrc or code ~/.bash_profile. Now, modify these two files as per the instructions.
In the question, I have also talked about VS Code activating Conda environments automatically. There's no issue with VS Code doing that since this is the default behavior.
I misinterpreted that as something that's an issue. But if anyone was looking to stop VS Code from automatically doing that, I would recommend trying to set this in the user settings:
"python.terminal.activateEnvironment": false
EDIT: A better solution than using source activate to get conda activate commands to work in the git bash terminal in VS Code:
Run conda init in the Git Bash Terminal in VS Code
Type in bash -l in VS Code's Git Bash terminal to launch your configured shell as a login shell
You should now be able to run conda activate commands per normal!
More info: bash -l runs your ~/.profile/~/.bash_profile/~/.zprofile scripts where the conda executable is actually referenced (but in which Git Bash as a integrated terminal does not run by default and refers to). Hence, git bash does not know where to search for conda when running conda activate commands and per Arafat's explanation above, running conda init changes the git bash PATHs in this .bash_profile file, but is ineffectual as the git bash terminal in VS Code doesn't actually refer to this file! Further info in VS Code's official docs.
Supplementing the explanation of the accepted answer, I've posted a solution that worked for me here that might possibly help others (changing user settings did not solve the issue for me). Link could also point to other working solutions if the below or accepted answer above doesn't work.
NOTE: Please read Arafat's answer before attempting the source activate method below to understand why it's not normally recommended. That said leaving it up as it still solves the problem.
Here's what worked for me using the Git Bash terminal in VS Code on
windows in succinct steps:
source activate env-name - You should see your line appended by the (base) tag now.
After calling on source activate, I've found following conda activate commands to work: i.e. conda activate env2-name
What didn't work for Git Bash (as a VS Code terminal) for me: activate
env-name and conda activate env-name.
A year later I am still running into this issue. The following is a streamlined and updated approach based on Arafat's answer.
Install Git Bash
Configure Git Bash to be used in VSC (see How do I use Bash on Windows from the Visual Studio Code integrated terminal?)
Open the git bash Terminal from VSC
If conda activate is run successfully, skip the rest
run
conda init bash
Check for the exiting bash dot files:
ls -al ~/.bash*
Likely only one of '.bashrc' and '.bash_profile' exist
Check the existing dot file for conda initialization code
e.g.
cat ~/.bash_profile
This included in my case '>>> conda initialize >>> ...' code
(But, and this is the source of the problem, it is not executed when the terminal is opened. To check which of the files is executed simple add 'echo hello-X' to each of them.)
To fix the problem, we must create the missing dot file and make it execute the OTHER previously existing one:
tee -a ~/.bashrc << END
if [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi
END
Reopen the Terminal in VSC

Anaconda and Git Bash in Windows - conda: command not found

I've installed Anaconda and set Path environment variable to C:\Anaconda3; C:\Anaconda3\Scripts.
Then I try to run in Git Bash
conda install python
But there is an error message "bash: conda: command not found". I would like to know why.
To be able to run conda on gitbash you need to add it to the path. Many times I've seen that's done by default - as shown in the setup for this workshop. If it doesn't, as it seems your case, then you can run their setup directly by running:
. /c/Anaconda3/etc/profile.d/conda.sh
After running that you should be able to run conda commands.
To keep this setup permanently you can add such line on your .profile or .bashrc file (read more about their differences). A way of doing so is running the follwing:
echo ". /c/Anaconda3/etc/profile.d/conda.sh" >> ~/.profile
You may encounter problems if the path where Anaconda was installed contains spaces (e.g., C:\Program Files). In that case you would need to change the anaconda location or edit conda.sh script with something like:
sed -e '/^_CONDA_EXE=.*/a alias myconda="${_CONDA_EXE/ /\\\\ }"' \
-e 's/\$_CONDA_EXE/myconda/g' /c/Program\ Files/Anaconda3/etc/profile.d/conda.sh > conda_start.sh
This sed command inserts a new alias definition myconda which changes the anaconda path from Program Files to Program\ Files so bash doesn't stop with an error like this one:
bash: /c/Program: No such file or directory
The second sed command replaces the _CONDA_EXE variable by the new alias created.
Since the above doesn't modify the file provided by anaconda, you will need to update your .profile file to load the file we've just created, conda_start.sh, instead.
First, you need to move to the directory where conda is located.
(some path such as C/Anaconda3/Scripts or ../miniconda3/Scripts or anaconda3/bin)
then, open the terminal.
(or, if you use Windows and can't find where the conda is, try moving to directory such as C:\Users\User_Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) and open the Anaconda prompt.)
Then, do this:
conda init
or something like
conda init bash
if you use Mac OS:
conda init zsh
will work well.
if you wanna use different shell,
conda init [shell_name]
[shell_name] can be: bash, cmd.exe, fish, powershell, tcsh, xonsh, zsh, etc.
use conda init --help for more info.
Joining #dvdgc13. In my case, I fixed the problem by adding
. C:/Users/user/Anaconda3/etc/profile.d/conda.sh
to my .bash_profile.
I tried to do the same thing as you did but I couldn't get it to work. starriet had the working answer but I am going to make it easier for everyone else reading. You can directly open command windows with explorer instead of struggling with paths.
Find your Anaconda3 folder with Windows Explorer This could be a user install where would be in your user folder such as "C:/Users/your_name/Anaconda3".
Shift + Right Click on the explorer and click on "Open PowerShell Windows Here". Note: you can just click "Git Bash" and you open Bash instead which makes no difference to the command.
Type in "conda init" in the PowerShell window. This works even if you don't have the right paths because the command line looks for the right exe in the current dictionary. If you scroll down in the explorer, you should be able to find it.
My PowerShell window would look a little different than yours because of my prompt but it makes no difference.
Exit the PowerShell and open Git Bash. Type "conda" to confirm that things work.
For MAC users, do this:
$ echo ". /usr/local/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc
$ source ~/.bashrc
I tried many ways, but they are incomplete until I run the following commands:
Go to the path of anaconda3 is C:\Users\USER_NAME\anaconda3 and open commend line over there and print the following: (YOUR_PATH = C:\Users\USER_NAME\anaconda3 )
echo 'export PATH="$PATH:[YOUR_PATH]:[YOUR_PATH]/Scripts"' >> .bashrc
echo 'alias python="winpty python.exe"' >> .bashrc
If Git bash is opened, close it and reopen it again and type the following to make sure anaconda and python work without problems:
conda --version
python -- version
If you see the versions are printed, everything works well.
In my case conda command was recognised in cmd, but not in bash. I used conda init bash instead of simple conda init in cmd.
This command modified the .bash_profile file, which was residing in my C:\Users\xyz directory, and added the following code in it
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/C/Users/Saifullah/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
# <<< conda initialize <<<
now it is working in bash terminal too.

How to insert the Homebrew directory at the top of your PATH environment variable?

I need little help here. For your information, I'm a very new to Python, and just trying to tinker with it. So, I have this website 'The hitchhiker's guide to python'. Now, I'm on a section of 'Installing Python 3 on Mac OS X'. Here is the link -> http://docs.python-guide.org/en/latest/starting/install3/osx/#pip
Anyway I wanted to do it right, so freshly formatted my Mac, and Xcode as well. And I followed the instruction which says 'xcode-select --install' . After that, I started install homebrew within the terminal $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
I guess I coped with this until now, but here is the problem occurs.
He says
Once you’ve installed Homebrew, insert the Homebrew directory at the
top of your PATH environment variable. You can do this by adding the
following line at the bottom of your ~/.profile file
So, with some searches, I edited my path in nano. by following
sudo nano /etc/paths
/usr/local/bin
/usr/local/sbin <<<--When I opened the paths, there wasn't this 'usr/local/sbin' So I typed it.
/usr/bin
/bin
/usr/sbin/
/sbin
When I opened the path, there was no '/usr/local/sbin'. so I typed it.
And I quit the terminal, echo the path out, nothing happend.
If I do which python it shows me /usr/bin/python.
I do have python3 installed, But when I do python -V, it's still
Python 2.7.10
How can I insert the Homebrew directory at the top of your PATH environment variable?
By means, How can I set my mac to set python3 to default???
Appreciate it in advance!
You misunderstood the instructions about the PATH. PATH is an environment variable which can be set in the .profile file in your home directory (create it if it doesn't exist), and you need to copy exactly what the page said to the bottom of the file:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
Once this is done, restart your Terminal and you should be able to use the python3 command.
Go to your terminal and run:
$ which brew
/usr/local/bin/brew
you will get your brew path and make sure you add this path to ~/.profile PATH like this:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
Then run this to make changes effective:
$ source ~/.profile
The file in /etc/ is only run at startup, and is global over all users. I suggest you use the files in your home directory (.bash_profile or .zshrc depending on your shell). These files are read every time a terminal is opened.
Add this line:
export PATH=/usr/local/sbin:$PATH
To update an existing terminal, you can update the settings by
> source ~/.bash_profile

running a virtualenv python under Xcode

So far I've been able to work with Python 3 and Xcode 5.1.1 by editing the scheme, pointing the Run executable to python3 and then adding some arguments as in the following picture:
But now I would like to work with isolated Python environments through virtualenv. I can do this through the terminal, as I just have to type workon pydev where pydev is my Python environment. But I have no idea of how to modify my Xcode configuration so that I can run within a Python environment. Is there an environmental variable or something I can set to make this happen?
UPDATE
So I have a partial answer but I still can't make it work on Xcode. I created a simple bash script:
#!/usr/bin/env bash
source ~/.bash_profile
workon pydev
python3 src/__main__.py
The source is needed because otherwise the workon command doesn't work (another file provided by the virtualenv package is sourced inside .bash_profile. I can run the script in the Terminal, but the problem now is that Xcode doesn't like it:
Xcode cannot run using the selected destination.
Choose a destination with a supported architecture in order to run on this system.
I solved it, so you have to add the following pre-action to Xcode.
The source is needed because otherwise the workon command doesn't work (another file provided by the virtualenv package is sourced inside .bash_profile.

How to run Conda?

I installed Anaconda and can run Python, so I assume that I installed it correctly. Following this introductory documentation, I am trying to install Python v3.3, so I am copying and pasting the following line into my console:
conda create -n py33 python=3.3 anaconda
However, that gives me an error:
-bash: conda: command not found
What do I need to do to run Conda?
I am working on a Linux system.
you might want to try this:
for anaconda 2 :
export PATH=~/anaconda2/bin:$PATH
for anaconda 3 :
export PATH=~/anaconda3/bin:$PATH
for anaconda 4 :
Use the Anaconda Prompt
and then
conda --version
to confirm that it worked.
The export PATH=~/anaconda3/bin:$PATH works but stops when you exit the terminal in order change that you have to run sudo nano ~/.bashrc and then copy the path into the file and save it after that you activate the changes using source .bashrc.
check with conda install anaconda-navigator
if not installed follow the anaconda install instructions again
follow along with this video
https://youtu.be/Pr25JlaXhpc
It turns out that I had not set the path.
To do so, I first had to edit .bash_profile (I downloaded it to my local desktop to do that, I do not know how to text edit a file from linux)
Then add this to .bash_profile:
PATH=$PATH:$HOME/anaconda/bin
Use conda init
As pointed out in a different answer, manually adding Conda on $PATH is no longer recommended as of v4.4.0 (see Release Notes). Furthermore, since Conda v4.6 new functionality to manage shell initialization via the conda init command was introduced. Hence, the updated recommendation is to run
Linux/UNIX (OS X < 10.15)
./anaconda3/bin/conda init
Mac OS X >= 10.15
./anaconda3/bin/conda init zsh
Windows
./anaconda3/Scripts/conda.exe init
You must launch a new shell or source your init file (e.g., source .bashrc) for the changes to take effect.
Details. For an in-depth look at exactly what conda init does see this answer.
Alternative shells
You may need to explicitly identify your shell to Conda. For example, if you run zsh (Mac OS X 10.15+ default) instead of bash then you would run
./anaconda3/bin/conda init zsh
Please see ./anaconda3/bin/conda init --help for a comprehensive list of supported shells.
Word of Caution
I'd recommend running the above command with a --dry-run|-d flag and a verbosity (-v) flag, in order to see exactly what it would do. If you don't already have a Conda-managed section in your shell run commands file (e.g., .bashrc), then this should appear like a straight-forward insertion of some new lines. If it isn't such a straightforward insertion, I'd recommend clearing any previous Conda sections from $PATH and the relevant shell initialization files (e.g., bashrc) first.
Again, for those interested, there is an in-depth look at how it works, in this answer.
Potential Automated Cleanup
Conda v4.6.9 introduced a --reverse flag that automates removing the changes that are inserted by conda init.
If you have installed Anaconda but are not able to load the correct versions of python and ipython, or if you see conda: command not found when trying to use conda, this may be an issue with your PATH environment variable. At the prompt, type:
export PATH=~/anaconda/bin:$PATH
For this example, it is assumed that Anaconda is installed in the default ~/anaconda location.
This info is current as of today, August 10, 2016. Here are the exact steps I took to fix this using methods posted above. I did not see anyone post: export PATH=$PATH:$HOME/anaconda/bin (you need to add export to the beginning of the line).
Here it is, step-by-step:
For anyone running into the same problem while using oh-my-zsh, you need to do the following:
-Open your .zshrc in your terminal. I am using iTerm 2 and have Sublime Text 3 as my default text editor:
subl ~/.zshrc
-Once the file opens in your text editor, scroll to the very bottom and add:
export PATH=$PATH:$HOME/anaconda/bin
-Save the file, then close it.
-Close your terminal, then relaunch it.
-Once back in your terminal, type:
conda --v
You should then see the version of conda installed printed on your screen.
If you're using zsh, then after doing that, your terminal may show you zsh: command not found: rvm-prompt.
The solution is:
add alias rvm-prompt=$HOME/.rvm/bin/rvm-prompt within .zshrc file.
type source .zshrc.
Then the zsh: command not found: rvm-prompt will disappear.
My env: macOS & anaconda3
This works for me:
$ nano ~/.bash_profile
Add this:
export PATH=~/anaconda3/bin:$PATH
*The export path must match with the actual path of anaconda3 in the system.
Exit out and run:
$ source ~/.bash_profile
Then try:
$ jupyter notebook
Edit ~/.bash_profile, add this to it.
PATH=$PATH:$HOME/anaconda/bin
then run
source ~/.bash_profile
Hope can help you.
I'm on High Sierra MAC OS and just installed Anaconda3 via HomeBrew command. I had issue with running :
conda
It'd also give me:
-bash: conda: command not found
I tried running:
export PATH=~/anaconda3/bin:$PATH
but it needs ENTIRE path. so here are the correct steps:
$ nano ~/.bash_profile
Now export the ENTIRE path, in my case it was:
export PATH=/usr/local/anaconda3/bin:$PATH
Exit out and run:
$ source ~/.bash_profile
Then try:
$ conda
it'll output:
$ conda --version
conda 4.4.10
If you have just installed anaconda and got this error, then I think you forgot to run this command :
source ~/.bashrc
This will enable you to make use of anaconda in terminal.
This may seems simple but many (including me) do this mistake.
If the error is still persisting, you have to verify if anaconda location is added to PATH in your system.
Once you add it, you'll be fine
If you have installed Anaconda and have definitely said yes to the:
Do you wish the installer to prepend the Anaconda install location to PATH in your /home/name/.bashrc ? [yes¦no]
question then you maybe just need to restart your terminal window. The change won't take effect until you either (1) close and reopen the current window or (2) just open and start working in a new window
Basically, open a new console window and see if it works now.
For Windows:
A recent Anaconda(version 4.4.0) changed some directories.
You can find "conda" in Anaconda3/Scripts, instead of Anaconda3/bin.
Mostly it is because when we install Anaconda in the end it adds the anaconda path to PATH variable in .bashrc file.
So we just need to restart the terminal or just do
source ~/.bashrc
if still it don't work then follow this commands.
cat >> ~/.bashrc
paste the below command for anaconda3
export PATH=~/anaconda3/bin:$PATH
hit Enter then ctrl+d
source ~/.bashrc
Using the export PATH= strategy with conda activate will result into a warning message for conda>=4.4.
The recommended way (see this release note, and this post) to do is to remove the export PATH=... line and add instead in your .bashrc (.bash_profile) the line:
. ~/anaconda2/etc/profile.d/conda.sh
Furthermore, if you want conda to be activated by default, add:
conda activate
If you have installed anaconda, but if you are not able to execute conda command from terminal, it means the path is not probably set, try :
export PATH=~/anaconda/bin:$PATH
See this link.
I also was facing the same issue ,this might be the simplest possible solution
source anaconda/bin/activate
for anaconda2 use
source anaconda2/bin/activate
depending on the name of the directory , then execute your command i.e. conda --create
Run
cat ~/.bash_profile
to check if anaconda is there. If not you should add its path there.
If conda is there copy the entire row that you see the Anaconda there from "export" to the end of line.
like this:
export PATH=~/anaconda3/bin:$PATH
Run this in your terminal.
Then run
conda --version
to see if it is exported and running!
System: macOS
I installed Anaconda first, and everything worked well. Then I installed iTerm2 and when I typed Python iTerm2 gave me the default Python. Here is how to find your Anaconda Python back:
Open your .zshrc file. For example, vim ~/.zshrc
Then add export PATH="/Users/yourusername/anaconda2/bin:$PATH" to the last line of the file. Note that you need to replace the yourusername to your user name and make sure you have anaconda2. An easy way is to copy this line from ~/.bash_profile
Save the file, close it, relaunch the terminal and now Anaconda Python should be back.
Answer for
Anaconda3 5.2.0 installer
macOS HighSierra
ZSH
Unfortunately, the installer puts the PATH definition only into .bash_profile, but not the .zshrc config.
Contrary to the given answers, it doesn't (necessarily) install in ~/anaconda3/, but instead in /anaconda3/.
The PATHdefintion in .zshrc must therefore be this:
...
# Anaconda3
export PATH="/anaconda3/bin:$PATH"
...
Temporary solution:
$anaconda/bin/conda create -n py33 python=3.3 anaconda
If you have just installed MiniConda or Anaconda make sure you re-run your terminal.
From this, I mean close and open your terminal and then try conda list to verify your installation
For me, this worked!!
To edit bashrc in Ubuntu
$ /usr/bin/vim ~/.bashrc
type PATH=$PATH:$HOME/anaconda3/bin
Press Esc and :wq to save bashrc file and exit vim
enter image description here
then
$ export PATH=~/anaconda3/bin:$PATH
and type $ source ~/.bashrc
Now to confirm the installation of conda type
$ conda --version
Open your terminal and type the following command to add anaconda to environment path
for anaconda 2 :
export PATH=~/anaconda2/bin:$PATH
for anaconda 3 :
export PATH=~/anaconda3/bin:$PATH
Then to check the conda version just type,
conda --version
Create an environment using the following command,
conda create --name myenv
Activate the source using,
source activate myenv
Then your anaconda IDE is ready!!!
If you installed Anaconda with Visual Studio 2017 for Windows,
conda executable is in this path or similar.
In my case path is this:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Scripts
Steps to add it to your PATH:
On the Windows desktop, right-click My Computer.
In the pop-up menu, click Properties.
In the System Properties window, click the Advanced tab, and then click Environment Variables.
In the System Variables window, highlight Path, and click Edit.
Add your path and restart your cmd.
You will be able to execute conda
Happy coding!
I am setting up a virtual machine running Ubuntu. I have anaconda 3 installed in the "Home" folder. When I typed "conda" into the terminal I was getting the error "conda: command not found" too.
Typing the code below into the terminal worked for me...
export PATH=$PATH:$HOME/anaconda3/bin
to check it worked I typed:
conda --version
which responded with the version number.
In my case conda Path was properly set (in .bashrc) by the conda installation bash. But to make it works I had to give executable file permissions to files in bin sub folder with chmod +x *.
My system info:
conda 4.2.9
Operating System: Debian GNU/Linux 8 (jessie)
Kernel: Linux 3.16.0-4-amd64
Architecture: x86-64
You need to put Anaconda.sh to your /home/, then run it to install. After that, you can runexport PATH=~/anaconda3/bin:$PATH . Remark: do not run Anaconda.sh in download/ directily!!!!!
I had same issue. What I did, removed anaconda directory from the install location and re-install
after that it worked as I anticipated
First, check the location of anaconda, for me I installed anaconda3 at / directory which I access with /anaconda3
Then in your terminal, input export PATH="<base location>/anaconda3/bin:$PATH" for me it's export PATH="/anaconda3/bin:$PATH".
Finally, input source $/anaconda3/bin/activate. For you, just change to your location.
Now, you could try conda list to test.
Also, visit intallation guide
1. Check where you have installed Anaconda. In my case it looks like /home/nour/anaconda3/bin
Open your .bashrc file. For example $ gedit .bashrc
3. Add this export PATH = /home/nour/anaconda3/bin:$PATH line at the end of the file and save.
Reopen the terminal. Type conda --version
NOTE: Make sure path in line no. 1 and line no. 3 must be same. In my case /home/nour/anaconda3/bin .
The main point is that as of December 2018 it's Scripts not bin.
Updating $PATH in "git bash for windows"
Use one of these:
export PATH=$USERPROFILE/AppData/Local/Continuum/anaconda2/Scripts/:$PATH
export PATH=$USERPROFILE/AppData/Local/Continuum/anaconda3/Scripts/:$PATH
Updating $PATH in the windows default command line
Use one of these:
SET PATH=%USERPROFILE%\AppData\Local\Continuum\anaconda2\Scripts\;%PATH%
SET PATH=%USERPROFILE%\AppData\Local\Continuum\anaconda3\Scripts\;%PATH%
Updating $PATH in Linux
Change /app to your installation location. If you installed anaconda change Miniconda to Anaconda. Also, check for Script vs. bin,.
export PATH="/app/Miniconda/bin:$PATH"
You may need to run set -a before setting the path, I think this is important if you're setting the path in a script. For example if you have your export command in a file called set_my_path.sh, I think you'd need to do set -a; source("set_my_path.sh").
The set -a will make your changes to the path persist for your session, but they are still not permanent.
For a more permanent solution add the command to ~/.bashrc. The installers may offer to add something like this to your ~/.bashrc file, but you can do it too (or comment it out to undo it).
General Observations:
Background: I installed the 64 bit versions of Anaconda 2 and 3 recently on my Windows 10 machine following the recommended installation steps in December of 2018.
Adding conda also enables ipython, which works much better in the native Windows command line
Following the strongly recommended installation does not add conda or ipython to the path
Anaconda 3 doesn't seem to install a command prompt application, but Anaconda 2 did have a command prompt application
The /bin folder seems to have been replaced with Scripts
Poking around in the Scripts folder is interesting, maybe the Anaconda command prompt application is in there somewhere.

Categories