Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Astro Coke

[Python] Switching between python 2.x and 3.x 본문

Computer Setup

[Python] Switching between python 2.x and 3.x

astrodoo 2019. 3. 28. 08:20

source: https://towardsdatascience.com/environment-management-with-conda-python-2-3-b9961a8a5097

 

List your Environments

 

This command shows you all the This is a really helpful command to see what environments you have, but also to see what conda environment you are in.

 

> conda env list

 

 

Remove an Environment

 

If the name of your environment you want to remove is not subscribe, you will need to substitute "py36" for the name of your environment you want to remove.

 

> conda env remove --name py36

 

 

Switch the environment

 

> source activate py36

 

if you want to deactivate,

 

> conda deactivate

 

set the default environment

in .bashrc (linux) or .bash_profile (mac)

add the path of the environment to be defult:

 

e.g.) py36 environment

 

export PATH="/Users/astrodoo/anaconda2/envs/py36/bin:$PATH"

source activate py36

 

Disable prompt change

 

conda config --set changeps1 False

 

or add 

 

changeps1: False

 

in .condarc

 

 

Using Both Python 2.x and Python 3.x Environments in IPython Notebook

 

While this section of the post was largely taken and improved from stackoverflow, I feel like it is important to go over how and go over some technical issues people run into. The main idea is to have multiple ipython kernels. The package nb_conda_kernels will automatically detect different conda environments with notebook kernels and automatically register them.

  1. Make sure you have anaconda 4.1.0 or higher. Open a new terminal and check your conda version by typing

checking conda version

if you are below anaconda 4.1.0, type conda update conda

2. Next we check to see if we have the library nb_conda_kernels by typing

Checking if we have nb_conda_kernels

3. If you don’t see nb_conda_kernels type

Installing nb_conda_kernels

4. If you are using Python 2 and want a separate Python 3 environment please type the following

py36 is the name of the environment. You could literally name it anything you want.

If you are using Python 3 and want a separate Python 2 environment, you could type the following.

py27 is the name of the environment. It uses python 2.7.

5. Close your terminal and open up a new terminal. type jupyter notebook

6. Click new and you will see your virtual environment listed.