Terminal Command Not Working For Mac After Installing Anaconda - python

I just installed Spyder through Anaconda for Python on my Macbook Air. I'm trying to launch the App through the terminal but i get this error and have no idea how to solve it. FYI, this is my first time being in the terminal, I'm completely LOST! Any command you see that i ran is what i saw online while trying to solve the problem.Thanks.

Looks like you need to fix your $PATH
Run echo $PATH to see your current PATH, then add the Anaconda Path before it. In ~/.bash_profile:
export PATH="/Users/username/anaconda/bin:$PATH"
Once you've updated your bash_profile, you'll need to source ~/.bash_profile, or run that same export statement in your current shell session.

Related

System crashes each time i run python command in Terminal, how to get rid of /opt/miniconda3/bin/python?

please I need your help here!
My system crashes each time i run a python command in terminal. When i run something like python app.py, my Mac will crash and bounce, and reset.
In Terminal,
When i run python -V, it returns Python 3.7.6,
When i run python3 -V, it returns Python 3.8.5
When i run which python, it returns /opt/miniconda3/bin/python.
A moment ago, i was trying to build a standalone app, and turned on virtualenv. However no matter how hard i tried, i failed. Then i deleted the virtualenv folder in the app folder.
Perhaps during the development processes, in Visual Studio Code, i accidentally "linked" the virtualenv with the python interpreter 3.7 (/opt/miniconda3/bin/python), which was set as the default python system long ago (i can't even recall when and how). After the virtualenv folder deletion, i remember the interpreter had the word "cached" in the front of the python version. Somehow i turned on and off this and that, and restarted the app, i have get rid of the word "cached". But the system still crashes .
My Mac crashes now every time i run a python command in Terminal. Please help!
i even have tried update conda update conda, it says no such directory,
ofcoruse i then tried update miniconda, same answer.
You should remove it from your path.
To do so, check for the miniconda3 entry in the file named ~/.bashrc, ~/.bash_profile, and /etc/profile file and comment out the line:
export PATH=/opt/miniconda3/bin:$PATH
by preceding it with the # character.

How does one connect a Jupyter Kernel to VS Code if one does not connect automatically?

I want to be able to have a working jupyter notebook working for VS code out of the box, with minimal work on my side.
I tried opening a jupyter notebook. I immediately found the interpreter and used my conda env with the command pellet (command + shift + P then in the drop down menu found my conda env). This seems to make the terminal work since which python points to the right place:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ which python
/Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python
also running python scripts from VS Code seems to be working fine too, see output:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ /Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python /Users/brandomiranda/automl-meta-learning/python_playground.py
x = 1
my_str = this is a string
y = 2
but when I try the jupyter notebook it doesn't work.
Most noticeably my VS code does not have a kernel connected, look at the screenshot:
I tried clicking on a couple of arrows as suggested on reddit (vs_code_jupyter_server_no_kernel_python_not):
When I try running things in my jupyter notebook I get the following error:
Error: Activating Python 3.7.6 64-bit ('base': conda) to run Jupyter failed with Error: StdErr from ShellExec, /Users/brandomiranda/.bashrc: line 31: jump-module.bash: No such file or directory
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
.
which is strange. My shell is not even bash so I don't know why that message is being shown to me (maybe VS Code doesn't know Mac OS Catalina uses zsh? not sure how to fix that for VS Code). Regardless, I proceeded to do what I think the error message is suggesting. So I did the following:
I ran conda init and then went down to the terminal inside vs code and restarted the shell by running zsh but the jupyter kernel still doesn't work on my notebook in vs code. Not sure what's wrong.
In addition, I did what the error message suggested:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ conda init zsh
no change /Users/brandomiranda/miniconda3/condabin/conda
no change /Users/brandomiranda/miniconda3/bin/conda
no change /Users/brandomiranda/miniconda3/bin/conda-env
no change /Users/brandomiranda/miniconda3/bin/activate
no change /Users/brandomiranda/miniconda3/bin/deactivate
no change /Users/brandomiranda/miniconda3/etc/profile.d/conda.sh
no change /Users/brandomiranda/miniconda3/etc/fish/conf.d/conda.fish
no change /Users/brandomiranda/miniconda3/shell/condabin/Conda.psm1
no change /Users/brandomiranda/miniconda3/shell/condabin/conda-hook.ps1
no change /Users/brandomiranda/miniconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change /Users/brandomiranda/miniconda3/etc/profile.d/conda.csh
no change /Users/brandomiranda/.zshrc
No action taken.
but it seems it made no difference.
Any idea how to fix this?
I was suggessted by the developers of the VS code python extension to follow whatever they did here:
https://github.com/microsoft/vscode-python/issues/9566
but I can't figure out exactly it is they want me to do.
How do I fix this?
Related resources:
reddit: https://www.reddit.com/r/vscode/comments/eq2bfv/vs_code_jupyter_server_no_kernel_python_not/
gitissue: https://github.com/microsoft/vscode-python/issues/9636
I initially thought it was a conda issue so I looked into this question: Activate conda environment stopped working in vscode
https://www.reddit.com/r/vscode/comments/eshxka/how_does_one_connect_a_jupyter_kernel_to_vs_code/
https://www.quora.com/unanswered/How-does-one-connect-a-Jupyter-Kernel-to-VS-Code-if-one-does-not-connect-automatically
You need to select the python interpreter for jupyter, you can do it by following the step
Open command panel
Mac: CMD+Shift+P
PC: CTRL+SHIFT+P
Then search for select Interpreter to start jupyter server then hit enter, it will list all the interpreter, then select any interpreter and done!
it's just a one time process, after this, it will get connected automatically.
As bizarre as it seems, I also noticed this the other day and the only thing that works so far for me is to open VS Code by launching it from the Anaconda Navigator:
Then I get, as expected:
If you see the very long discussion I had in the git issue (https://github.com/microsoft/vscode-python/issues/9566) once I removed all the errors thrown by my .bashrc and .zhrc, the jupyter feature in VS code started working for me again. It's super weird (specially because I am NOT using bash at all and I am using zsh as my shell, I would have expected VS code to be robust to my .SHELLrc files throwing errors but it's not).
If that doesn't work, then you might have to install the vsix view extension and install the ms-python-insiders.vsixlinked in the issue (https://github.com/microsoft/vscode-python/issues/9566).
If on Windows VSCode, what worked for me was installing and enabling the Python and Jupyter extensions, then CTRL+SHIFT+P, select Interpreter to start jupyter server. Those extensions were the bottleneck.

Linux: Conda not working on installing Anaconda

I have installed Anaconda for python2 as per official documentation. In the end I received message about successful installation. To check I typed ipython and its terminal is displayed successfully but on doing conda --version nothing comes. I have checked following:
which python : It gives /home/username/anaconda2/bin/python
sha of downloaded package: It is correct
Other Anaconda installed package (ipython): It's terminal comes up
which conda: /home/username/anaconda2/bin/conda
Closed terminal and again open it(mentioned in docs). Checked after shutdown also !
On doing anaconda-navigator following message comes:
Please activate the conda root enviroment properly before running the
anaconda-navigator command.
To activate the environment please open a terminal and run:
source /home/username/anaconda2/bin/activate root
For more information please see the documentation at:
https://docs.anaconda.com/anaconda/navigator/
On doing as suggested above, nothing happens and the problem persists. Since I am new to this, might be missing something tivial, please suggest?
I was facing the exact same issue on Ubuntu 17.04 x64. In my case it was the usage of a different shell than the default (bash).
I installed the program using my ZSH shell.
During installation it asks:
Do you wish the installer to prepend the Anaconda<2 or 3> install
location to PATH in your /home/user/.bashrc ?
That made me try to run the Anaconda Navigator using bash shell (just use the bash command to switch). And yes it worked.
If you look into the .bashrc you will notice that the installer appended something like:
export PATH="/home/user/anaconda2/bin:$PATH"
If you export the path to ZSH (or any other shell you use) then it will work with your shell as well. In the case of ZSH just copy the export PATH line to the end of .zshrc

How to change python version in Mac terminal?

I installed python3 in my macbook.
but when I open terminal, type which python, it returns
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
So how can I change to the python3 for temporal use? I don't want to change the system default.
The reason why I change this is because I installed jupyter as pip3 and I want to open ipython file, when I type jupyter notebook, it says command not found, so I realise it because the python versions.
To change to python3, you can use the following command in terminal
alias python='python3'
you can also add this into ~/.bash_profile file
Edit you ~/.bash_profile and add the following line:
export PATH="$PATH:/path/to/your/Python/3.6/bin"
after that execute this once
source ~/.bash_profile
or restart the terminal
Does bash report that the command is not found when you enter 'jupyter notebook' as a command?
Pip should automatically make Jupyter available in $PATH but this may not be the case here if 'jupyter' is not a recognised command
Conversely if #Kallz's answer was successful then:
If you were looking for a consistent temporal environment for Jupyter where Jupyter runs in version x and you terminal shell/all other directories run version y, then you should refer to this answer about pyenv, which helps manage python versions and create Python 'environments'
If you can determine the specific directory location which executes Jupyter (I have no specific knowledge of Jupyter myself to help with this), then you can set a 'local' pyenv for the executing file location and a 'global' env for the version you want to use for shell etc., thus constraining to the correct version for both purposes.
See a setup tutorial here

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