Поиск по блогу

воскресенье, 25 сентября 2016 г.

Упражняемся с Conda (Anaconda) и учимся переключать окружение Python

Год назад я попробовал разобраться с настройкой переменных окружения для переключения между версиями iPython, но навалился фронтенд (с заказами), так что пришлось "вспоминать" javascript и осваивать nodejs... Здесь я возвращаюсь к этой задачке (в плане софт для статичтических исследований, а он под Python 3). Проверил актуальност старого поста, нашел "новую" документацию. Все наладил при помиощи activate py35, jupyter notebook

Changing your Python version with Anaconda
Managing Python
Anaconda documentationpowered by Continuum Analytics Home

A node.js kernel for jupyter/ipython
Jupyter Nodejs
IPython and Jupyter notebook This section focuses on IPython and Jupyter notebook and how they interact. This model is often called a REPL, or Read-Eval-Print-Loop.


plot.ly Plotly CLOUD

Начнем с конца, вот, как просто можно переключить окружение

In [ ]:
C:\Users\alter_000\.ipython\kernels>python --version
Python 2.7.11 :: Anaconda 2.3.0 (64-bit)

C:\Users\alter_000\.ipython\kernels>conda info --envs
# conda environments:
#
py35                     C:\Users\alter_000\Anaconda\envs\py35
root                  *  C:\Users\alter_000\Anaconda

Третий Питон уже установлен, его нужно просто активировать, пояснения ниже после conda help. Если бы третьего питона не было, то его можно было бы загрузить, вот пример из документации

In [ ]:
#To create a new environment, use the conda create command, followed by any name you wish to call it:

conda create --name snowflakes biopython
In [ ]:
C:\Users\alter_000\.ipython\kernels>activate py35
Deactivating environment "C:\Users\alter_000\Anaconda"...
Activating environment "C:\Users\alter_000\Anaconda\envs\py35"...

[py35] C:\Users\alter_000\.ipython\kernels>conda info --envs
# conda environments:
#
py35                  *  C:\Users\alter_000\Anaconda\envs\py35
root                     C:\Users\alter_000\Anaconda


[py35] C:\Users\alter_000\.ipython\kernels>python --version
Python 3.5.0 :: Anaconda 2.4.0 (64-bit)

[py35] C:\Users\alter_000\.ipython\kernels>

[py35] - теперь перед каждой строкой в терминале. Это значит, что данное окно терминала работает с третьим питоном

Команда activate py35

In [ ]:
[py35] C:\Users\alter_000\.ipython\kernels>conda help
usage: conda-script.py [-h] [-V] [--debug] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    info         Display information about current conda install.
    help         Displays a list of available conda commands and their help
                 strings.
    list         List linked packages in a conda environment.
    search       Search for packages and display their information. The input
                 is a Python regular expression. To perform a search with a
                 search string that starts with a -, separate the search from
                 the options with --, like 'conda search -- -h'. A * in the
                 results means that package is installed in the current
                 environment. A . means that package is not installed but is
                 cached in the pkgs directory.
    create       Create a new conda environment from a list of specified
                 packages.
    install      Install a list of packages into a specified conda
                 environment.
    update       Update conda packages to the current version.
    upgrade      Alias for conda update. See conda update --help.
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove. See conda remove --help.
    run          Launches an application installed with conda. To include
                 command line options in a command, separate the command from
                 the other options with --, like conda run -- ipython
                 --matplotlib
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (C:\Users\alter_000\.condarc) by default.
    init         Initialize conda into a regular environment (when conda was
                 installed as a Python package, e.g. using pip). (DEPRECATED)
    clean        Remove unused packages and caches.
    package      Low-level conda package utility. (EXPERIMENTAL)
    bundle       Create or extract a "bundle package" (EXPERIMENTAL)

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.
  --debug        Show debug output.

[py35] C:\Users\alter_000\.ipython\kernels>

Если открыть новое окно терминала (CMD Windows), то там будет старый Python - 2.7

Теперь попробуем обновить [py35]Python

[py35] C:\Users\alter_000.ipython\kernels>conda update python Fetching package metadata: .... Solving package specifications: ..........

Package plan for installation in environment C:\Users\alter_000\Anaconda\envs\py35:

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
vs2015_runtime-14.0.25123  |                0         1.9 MB
python-3.5.2               |                0        30.3 MB
anaconda-custom            |           py35_0          13 KB
------------------------------------------------------------
                                       Total:        32.3 MB

The following NEW packages will be INSTALLED:

vs2015_runtime: 14.0.25123-0

The following packages will be UPDATED:

python:         3.5.0-2           --> 3.5.2-0

The following packages will be DOWNGRADED:

anaconda:       2.4.0-np110py35_0 --> custom-py35_0

Proceed ([y]/n)? y

Fetching packages ... vs2015_runtime 100% |###############################| Time: 0:00:03 549.60 kB/s python-3.5.2-0 100% |###############################| Time: 0:00:50 633.85 kB/s anaconda-custo 100% |###############################| Time: 0:00:00 93.97 kB/s Extracting packages ... [ COMPLETE ]|##################################################| 100% Unlinking packages ... [ COMPLETE ]|##################################################| 100% Linking packages ... [ COMPLETE ]|##################################################| 100%

[py35] C:\Users\alter_000.ipython\kernels>

Прекрасно, теперь посмотрим, какая здесь версия Ipython

[py35] C:\Users\alter_000.ipython\kernels>conda update ipython Fetching package metadata: .... Solving package specifications: ..........

Package plan for installation in environment C:\Users\alter_000\Anaconda\envs\py35:

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
wcwidth-0.1.7              |           py35_0          21 KB
win_unicode_console-0.5    |           py35_0          27 KB
prompt_toolkit-1.0.3       |           py35_0         308 KB
traitlets-4.2.1            |           py35_0         112 KB
ipython-5.1.0              |           py35_0         1.0 MB
------------------------------------------------------------
                                       Total:         1.5 MB

The following NEW packages will be INSTALLED:

prompt_toolkit:      1.0.3-py35_0
wcwidth:             0.1.7-py35_0
win_unicode_console: 0.5-py35_0

The following packages will be UPDATED:

ipython:             4.0.0-py35_1 --> 5.1.0-py35_0
traitlets:           4.0.0-py35_0 --> 4.2.1-py35_0

Proceed ([y]/n)? y

Fetching packages ... wcwidth-0.1.7- 100% |###############################| Time: 0:00:00 146.95 kB/s win_unicode_co 100% |###############################| Time: 0:00:00 192.55 kB/s prompt_toolkit 100% |###############################| Time: 0:00:01 288.57 kB/s traitlets-4.2. 100% |###############################| Time: 0:00:00 217.20 kB/s ipython-5.1.0- 100% |###############################| Time: 0:00:02 397.15 kB/s Extracting packages ... [ COMPLETE ]|##################################################| 100% Unlinking packages ... [ COMPLETE ]|##################################################| 100% Linking packages ... [ COMPLETE ]|##################################################| 100%

[py35] C:\Users\alter_000.ipython\kernels>

In [ ]:
#Check Python versions
#Install a different version of Python
#Use a different version of Python
#Create Python 2 or 3 environments
#Create a Python 3.5 environment
#Create a Python 2.7 environment
#Update or Upgrade Python

Anaconda documentationpowered by Continuum Analytics Home

Anaconda is a free, easy-to-install package manager, environment manager, Python distribution, and collection of over 720 open source packages with free community support.

Hundreds more open source packages and their dependencies can be installed with a simple “conda install [packagename]”. It’s platform-agnostic, can be used on Windows, OS X and Linux. Or even easier, with new Anaconda Navigator for point and click install of environments and packages!

Conda, Anaconda and Miniconda

Conda, Anaconda and Miniconda Conda is an open source package management system and environment management system for installing multiple versions of software packages and their dependencies and switching easily between them. It works on Linux, OS X and Windows, and was created for Python programs but can package and distribute any software.

Anaconda is a distribution of Python containing Python, the conda package and environment manager, and many software packages for data analytics, data science, and scientific computing.

Miniconda is a mini version of Anaconda that includes just conda, its dependencies, and Python.

Any Anaconda package can be installed, removed, or updated with a single conda command after installing either Anaconda or Miniconda.



Посты чуть ниже также могут вас заинтересовать

Комментариев нет:

Отправить комментарий