Feeds:
Posts
Comments

Posts Tagged ‘python2’

Python 3 is gradually replacing Python 2 and is some of the newest Linux distributions like Fedora 23, it is installed as default.

So the question is if you have a library of python 2.x programs and you want to start learning python 3 and updating your codes, how can you install all the necessary packages like matplotlib, scipy, nompy, etc for both versions of python without messing up the system (since Linux desktops e.g. gnome, KDE, etc use python themselves).

Using Anaconda or Miniconda is one of the solutions. I tried miniconda since I do not want the whole Anaconda packages. According to its webpage, “Anaconda is a completely free Python distribution … It includes over 195 of the most popular Python packages for science, math, engineering, data analysis.” Both Anaconda and Miniconda are available for Linux, Mac OSX, and Windows. This way, you install a fresh version of python on your home directory, so doing anything to that does not affect your operating system.

Package installation using conda

Assume you have installed the package via your package manager. Now we have the command  “conda” available on command line. We can create two different environments for python 2 and python 3 packages:

$conda create -n mypy2 python=2 numpy

$conda create -n mypy3 python=3 numpy

and similarly you can install any other package, e.g. ipython, scipy, etc.

When the environment exist, you can use the normal “install’ command, like pip:

$ conda install numpy python=3

How to use it?

You can add something like the following to your .bashrc file:

export PATH=”/home/user_name/miniconda/bin:$PATH”

Then in the command line, you can activate the environment you want to work with:

$source activate mypy2

and you get an output in terminal like this:

discarding /home/user_name/miniconda/bin from PATH
prepending /home/user_name/miniconda/envs/mypy2/bin to PATH

When you are done, you can deactivate it:

$source deactivate

conda has easy options to install, update or remove a package or the whole environment.For instance, you can remove a whole environment at once:

$conda remove -n mypy2 –all

Typing “conda” in terminal, you get the help file:

$ conda
usage: conda [-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 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.
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. …
init             Initialize conda into a regular environment (when conda was installed as a Python package, e.g. using pip).
clean         Remove unused packages and caches….

Read Full Post »