After activating my anaconda Python 3.6 environment with
source activate py36
if I type
python
I go into python 3.6, as expected. But if I type
ipython
I go into an ipython environment based python 3.5.5, which is the same python version I get using
source activate base
and then
python
How can I get into an ipython environment using my anaconda-supplied python 3.6 interpreter? I have updated my anaconda environment with
conda update anaconda
and
conda update conda
Doing so does not help.
EDIT:
I hadn't realized that I had to install ipython separately for the python 3.6 environment; I'd thought it was a default part of anaconda. So
conda install ipython
after
source activate py36
did the trick. It doesn't seem optimal that after activating a particular environment, ipython may bring up a completely different anaconda-based environment. I'd prefer it to simply cause a "command not found" error. Bringing up the wrong environment without making it very obvious that that is happening could lead to confusion or problems.
I hadn't realized that I had to install ipython separately for the python 3.6 environment; I'd thought it was a default part of anaconda. So
conda install ipython
after
source activate py36
did the trick.
Have you done hash -r since entering the conda environment? Bash can cache paths to executables, so sometimes it doesn't use the one reported by which. Running hash -r resets the cache
Maybe you need also to update ipython conda update ipython
Related
I factory reset my MacBook and set up everything new to get rid of the multiple python version chaos I had on my old laptop.
Only thing I have installed atm is Anaconda. I created a new conda environment with python 3.9 and activated it in my zsh Terminal.
Still when I type "which python" it shows "/usr/bin/python" containing the MacBook standard Python2.7 version.
How can I make environments use their own dedicated version?
Edit for Code:
conda activate myenvname
which python
Trying to access the folder where the anaconda python should be leads to
cd: no such file or directory: /Users/marcus/anaconda/bin
When you install anaconda through the terminal it provides an option to prepend anaconda to the system path. make sure to choose yes. If you don't, you'll need to provide the full path to your anaconda installation when activating an environment, as in:
source <path to conda>/bin/activate
conda init
You'll need to do this in each shell session. Alternatively, you can use the anaconda terminal.
To fix this, Anaconda does not recommend fixing your path manually. I think this is because there are a number of things anaconda does when setting up your shell if you choose "yes". Instead, the recommended fix is to uninstall and re-install anaconda (and pick yes this time ;)).
See the Anaconda docs for more information.
I currently have python3 set as my default python version but I'd like to be able to switch back to python2 for certain things so I created a conda environment with the following command:
conda create -n py2 python=2.7
and then activated it with:
source activate py2
but when I do:
python --version
I still get
Python 3.6.8
What am I doing wrong here? I'm trying to download a conda package this is only python2 compatible but despite being in a python2 environment, it keeps telling me my python version is incompatible.
You might be running into the issue where you have multiple environments on top of one another.
Try running:
conda deactivate
multiple times in order to exit from all of the environments. Then run:
condo activate py2
I have quite some problems using python on my Mac. I need different versions from 3.5 to 3.7 and multiple packages for data science. Due to various instructions on the web I ended up installing python 3.6 itself, anaconda, pipenv and maybe more stuff I can't even remember.
I suppose there is no other way to eliminate this mess than to format everything and start over. Currently my terminal is showing some sort of prefix for the environment in the terminal. Something like:
(base) user#machine:~$:
How can I at least get rid of this environment prefix? It appeared after installing pipenv, which seems to have taken over my previous anaconda environments. I fear those vanish to when uninstalling pipenv.
The deactivate command alone will get you out of the currently activated virtual environment.
(base) user#machine:~$:
(base) user#machine:~$: deactivate
user#machine:~$:
As far as I know, this works across all operating systems.
Found the problem: Anaconda edited the .bash_profile which gets executed on the mac for each new terminal. I deleted the anaconda entry and the base prefix is gone.
Also, for anyone that is using zsh and Anaconda.
You can remove the entry Anaconda makes from the ~/.zshrc file in addition to the conda deactivate
Conda can be configured with command conda config
This command will remove message about the current environment:
conda config --set changeps1 no
This command will add messages about the current environment:
conda config --set changeps1 yes
https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#change-command-prompt
So I am used to typing source activate <environment> when starting a python Anaconda environment. That works just fine. But when I create new conda environments I am seeing the message on Ubuntu 16.04 to start the environments with conda activate instead. Besides the errors about how to set up my shell to use conda activate instead, I am still not clear on what is the difference between source activate ... and conda activate ... Is there a reason to change? Does anyone know the difference between these two commands? Thanks.
As of conda 4.4, conda activate is the preferred way to activate an environment. Generally, you won't find too much of a difference between conda activate and the old source activate, except that it's meant to be faster, and work the same across different operating systems (the latter difference makes conda activate a huge improvement IMO).
From the docs, regarding the release of conda version 4.4.0 (released December 2017):
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.
Here is one difference I found. source activate can be used at the beginning of a bash script to load conda environment, whereas conda activate would give me an error:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
This makes a huge difference to me since I often submit bash jobs to cluster and source activate is the only way to change conda environment.
Please correct me if anyone can use conda activate in a bash script.
I am not sure who might find this useful, but if
Your terminal lags due to the addition ">>> conda initialize
" in your .bashrc, then you decide to remove it and add anaconda to the path. If that is the case, then "conda activate env_name"
won't work, but "source activate env_name" will work, and then after
that, you can use either source activate or conda activate. If you
close the shell then to activate the environment again use "source
activate env_name"
FYI, removing ">>> conda initialize >>>" from my .bashrc file has
speedup my terminal and it doesn't lag anymore and I just default in
using "source activate env_name"
I have Ubuntu 20.04, conda version : 4.10.3, and conda-build version
: 3.21.5
I'm relatively new in macOS. I've just installed XCode (for c++ compiler) and Anaconda with the latest Python 3 (for myself). Now I'm wondering how to install properly second Anaconda (for work) with Python 2?
I need both versions to work with iPython and Spyder IDE. Ideal way is to have totally separate Python environments. For example, I wish I could write like conda install scikit-learn for Python 3 environment and something like conda2 install scikit-learn for Python 2.
There is no need to install Anaconda again. Conda, the package manager for Anaconda, fully supports separated environments. The easiest way to create an environment for Python 2.7 is to do
conda create -n python2 python=2.7 anaconda
This will create an environment named python2 that contains the Python 2.7 version of Anaconda. You can activate this environment with
source activate python2
This will put that environment (typically ~/anaconda/envs/python2) in front in your PATH, so that when you type python at the terminal it will load the Python from that environment.
If you don't want all of Anaconda, you can replace anaconda in the command above with whatever packages you want. You can use conda to install packages in that environment later, either by using the -n python2 flag to conda, or by activating the environment.
Edit!: Please be sure that you should have both Python installed on your computer.
Maybe my answer is late for you but I can help someone who has the same problem!
You don't have to download both Anaconda.
If you are using Spyder and Jupyter in Anaconda environmen and,
If you have already Anaconda 2 type in Terminal:
python3 -m pip install ipykernel
python3 -m ipykernel install --user
If you have already Anaconda 3 then type in terminal:
python2 -m pip install ipykernel
python2 -m ipykernel install --user
Then before use Spyder you can choose Python environment like below!
Sometimes only you can see root and your new Python environment, so root is your first anaconda environment!
Also this is Jupyter. You can choose python version like this!
I hope it will help.
This may be helpful if you have more than one python versions installed and dont know how to tell your ide's to use a specific version.
Install anaconda. Latest version can be found here
Open the navigator by typing anaconda-navigator in terminal
Open environments. Click on create and then choose your python version in that.
Now new environment will be created for your python version and you can install the IDE's(which are listed there) just by clicking install in that.
Launch the IDE in your environment so that that IDE will use the specified version for that environment.
Hope it helps!!