I have python 3.7.10, conda 4.12.0, and Spyder 5.0.5 installed on Windows 10, and I can see the list of environments with conda env list.
However, when I run conda activate <environment>, CommandNotFoundError appears:
In[1]: conda activate <env>
Note: you may need to restart the kernel to use updated packages.
CommandNotFoundError: 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'.
[...]
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
I like to change the environment without running Anaconda navigator (or close Spyder every time I change the environment).
Is there a command that I can run on Spyder console to change the virtual environment? Is it also possible to run different environments on different Spyder consoles?
To change environments you will need to change the interpreter preference and restart the console or create a new one. To change the interpreter preference you can go to Tools > Preferences > Python Interprer > Use the following Python interpreter and select there the path for the python.exe of the env you want to use.
For more info regarding how to use existing enviroments with Spyder: https://docs.spyder-ide.org/current/faq.html#using-existing-environment
Related
For some reason the jupyter notebooks on my VM are in the wrong environment (ie stuck in (base)). Furthermore, I can change the environment in the terminal but not in the notebook. Here is what happens when I attempt !conda activate desired_env in the notebook:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
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'.
# conda environments:
#
base * /anaconda
azureml_py36 /anaconda/envs/azureml_py36
azureml_py38 /anaconda/envs/azureml_py38
azureml_py38_pytorch /anaconda/envs/azureml_py38_pytorch
azureml_py38_tensorflow /anaconda/envs/azureml_py38_tensorflow
I tried the answers here (e.g., first running !source /anaconda/etc/profile.d/conda.sh).
I also tried activating the environment using source rather than 'conda activate': !source /anaconda/envs/desired_env/bin/activate. This runs but doesn't actually do anything when I see the current environment in conda env list
Edit: also adding that if I install a package in the (base) environment in the terminal, I still don't have access to it in jupyter notebook.
I'm the PM that released AzureML Notebooks, you can't activate a Conda env from a cell, you have to create a new kernel will the Conda Env. Here are the instructions: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-access-terminal#add-new-kernels
I installed latest version of Anaconda3-2020-02.
I was trying to follow this instruction in order to create environment for running with python==3.6 instead of python==3.7., because I have python 3.6. installed.
So, running the
conda create --name snakes python=3.6
and then activating my environment with conda activate snakes, it enters environment (snakes). However there are no anaconda packages inside like jupyter notebook or others, no anaconda-navigator... So whats the purpose of it and how can I run these programs from environment?
Also, for some reason (when I am not in the environment, just regular bash shell) $PATH is not set up to the /bin directory in anaconda, just to /condabin. Can you explain this also, because I am not able to run nothing except conda command from shell after recommended installation.
If by default after installation environment is not activated, you should activate it by sourcing a file anaconda3/bin/activate. You will see indicator (base) on the left of your bash prompt.
Good thing about anaconda3-2020-02 is that it is not messing with system python, as newest python is being launched inside environment and proper$PATH is set up just inside environment. If only, for some reason, specific version of python is needed, then it makes sense to set it up with this instruction. I would be just using default one with python 3.7 probably from (base) environment.
Keep in mind that by default anaconda components are not being set up inside new environment being created. In order to bring them, for example jupyter, you should run the command like this:
conda create --name snakes python=3.6 jupyter
When setting up a Pycharm development environment, I am trying to follow the following instruction, which is for Linux environment. However, my system is virtual environment created by Anaconda, running on Windows 10. How to add Pythonpath in Pycharm with respect to this kind of environment?
Add Libraries to PYTHONPATH
When running locally, the tensorflow/models/research/ and slim directories should be appended to PYTHONPATH.
This can be done by running the following from tensorflow/models/research/:
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Note: This command needs to run from every new terminal you start.
You may follow the following steps:
Get the Python executable path for Anaconda:
Go to window's "programs" and search for "Anaconda Command line" then right click on the properties and copy the path then go to the cmd terminal and type the path and then type python.exe at the end till you logged in the python interpreter. This may vary from an OS to another but this works for me under windows 7.
In Pycharm: Add a new Python interpreter by following exactly the instructions listed in https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html.
Use the Anaconda python executable path you got in step1 for the new interpreter called "Conda" for example. Set the new project to use "Conda" interpreter instead of the normal default Python interpreter.
Apply the new changes and restart Pycharm. Open the Settings/Preferences dialog box, and click Project Interpreter page to make sure that the project is pointing to "Conda" interpreter.
Hope this will help!
I can activate the Conda Environment with any problems from the bash shell. I can use this two options on bash:
source activate env_name
. activate env_name
But I am using the method exec of Node to run the activation of the environment. Node uses sh shell in order to run commands. I tried the commands above, but they did not work. I got this error
/bin/sh: 1: /env_name/bin/source: not found
So I had to use this command to run the environment
const child_process = require('child_process')
child_process.exec('bash -c "source activate env_name"')
Is there a better way to do this to make it work on Ubuntu?
I run this on Windows and it is enough to make it work
child_process.exec('activate env_name')
Conda doesn't do well right now (in conda 4.3.x) with shells that aren't "advanced" like bash and zsh. Pure posix dash and the busybox shells, for example, don't work right now.
Good new though... They soon will. Support for a larger variety of shells is a feature of conda 4.4. The base PR for this work was https://github.com/conda/conda/pull/5044, and there are several follow-ons.
Conda 4.4.0 should be released into canary in the next several weeks.
I've got anaconda installed and was able to create a Python 3.3 environment. I can switch to it and conda info -e shows that I've switched.
However, I'm confused about what to set my PATH variable to. If I hard code it to the exact env then it works, but I thought that the purpose of conda was to be able to switch easily, as well as update and maintain various environments separately.
Perhaps I misunderstood and there's no way around setting my PATH everytime...
In the Windows cmd shell, use the activate and deactivate commands to change the PATH automatically. For instance, if your environment is called python3, run python3 to "activate" (i.e., add to the PATH) the python3 environment. Use deactivate to remove it.