Showing posts with label environment. Show all posts
Showing posts with label environment. Show all posts

How to rename a conda environment

Seems need to create a clone and remove the old one based on the answer from https://stackoverflow.com/a/42231765


# create a clone environment

conda create --name new_name --clone old_name 

# remove the old one

conda remove --name old_name --all # or its alias: `conda env remove --name old_name`

How to Execute Python Script in Jupyter Notebook using a Specific Virtual Environment, How to list and remove kernels from Jupyter Notebook


# Suppose you are in an activate virtualenv named py2env

(py2env)$ 

# Then install jupyter within the active virtualenv
(py2env)$ pip install jupyter

# jupyter comes with ipykernel, but somehow you manage to get an error due to ipykernel, then for reference ipykernel package can be installed using:
(py2env)$ pip install ipykernel

# set up the kernel
(py2env)$ python -m ipykernel install --user --name py2env --display-name "Python2 (py2env)"

# Now we can start jupyter notebook
(py2env)$ jupyter notebook




How to list kernels of Jupyter Notebook

If we want to check the list of kernels in our Jupyter Notebook, and remove afterwards.

$ jupyter kernelspec list
This will give you a list of kernels as follows
Available kernels:
  hbnn            /home/parklize/.local/share/jupyter/kernels/hbnn
  iswctest        /home/parklize/.local/share/jupyter/kernels/iswctest
  milvus          /home/parklize/.local/share/jupyter/kernels/milvus
  py3.6           /home/parklize/.local/share/jupyter/kernels/py3.6
  py3.7tf2.3.0    /home/parklize/.local/share/jupyter/kernels/py3.7tf2.3.0
  py3.7tf2.4.1    /home/parklize/.local/share/jupyter/kernels/py3.7tf2.4.1
  pymc            /home/parklize/.local/share/jupyter/kernels/pymc
  xai             /home/parklize/.local/share/jupyter/kernels/xai
  python3         /home/parklize/anaconda3/envs/pymc_env/share/jupyter/kernels/python3

How to remove a kernel of Jupyter Notebook

If we want to remove one of them, for example, the following command removes the hbnn kernel.

$ jupyter kernelspec remove hbnn

How to create & remove another environment on Anaconda (e.g., python 2)

Create another environment on Anaconda,

e.g., if you installed default is python 3, and you want to use python 2:
- conda create -n python2 python=2.7 anaconda

which will create python 2.7 environment with the name "python2".


Remove a created environment

e.g., removing an environment named "Py3"
- conda env remove -n Py3


Activate and deactivate the environment (env):
- source activate python2
- source deactivate

You can install packages for python 2.* environment with the python2 env being activated


Use spyder with python 2.7

You can run the spyder app with python 2.7 by activating the python2 env, and type spyder in the command line.

- source activate python2
- spyder


In case the spyder is not automatically installed during creating the env, you should install it first.

- conda install -n python2 spyder