Installation, IDEs etc.
Last updated
Was this helpful?
Last updated
Was this helpful?
Python can be installed right away from the official site or use conda distros.
- Full distro with hundreds of shipped packages (not needed in reality)
- minimal distro with basic packages
Recommended as it comes with conda
package and env manager
After installation pip
tool (Python package manager) can be used to manage 3rd party packages
Main commands:
install, upgrade package and install requirements from a file:
uninstall package:
list and export all installed packages:
Similarly you can manage packages via conda
(if installed *conda distro):
Virtual environment is the way of isolation the Python installation from other environments allowing to maintain the same versions of all packages as it was planned/required/designed for. This allows to mimic the working environment on other system and contribute in the development. Also with this we can run tests of different Python programs with different dependencies locally, on remote machines or clouds.
There are quite a few possible solutions for virtualizing the environment:
Almost default solution (some part of it were integrated into Python 3.3 as module venv
). Very simple but robust way of creating an isolated environment at a given place.
The most popular modern method of virtual environment on production is using specialized Python distribution and it's own environment manager. You can create, export or delete environments.
It is the a de facto standard for data science or AI/ML-related projects.
Modern and slick packaging, dependency resolver and virtual env management tool. You can do some magic things like having separate dev/prod requirements, project relocation, publishing helpers.
Virtual environment creation tool which allows to keep different version of Python with different version of packages.
You need to install it via pip:
pip install virtualenv
Usage:
Better tool to manage different python virtual environment is virtualenvwrapper.
UNIX:
Windows clone:
Main feature is controlling all available environments with easy fast switching between them.
Installation:
pip install virtualenvwrapper
(or pip install virtualenvwrapper-win
)
There are two related terms: projects and virtual environments.
Virtual environment
Environment that lives inside $WORKON_HOME
(%WORKON_HOME%
)
Project
Directory with the code related to specific venv.
If venv was created with association to specific project dir (-a <path/to/project/
) - after switching to it virtualenvwrapper will chande current directory to project.
virtualenvwrapper VENV commands:
Create new venv:
mkvirtualenv [mkvirtualenv-options] [virtualenv-options] VENV_NAME
mkvirtualenv options:
-a project_path
Associate existing path as project directory
-i package
Install package in new environment
-r requirements_file
VENV_NAME
(must be last) - the name of resulted venv
List of all venvs:
workon
RECOMMENDED
lsvirtualenv
Switch to another venv:
workon VENV_NAME
Deactivate current venv:
deactivate
virtualenvwrapper PROJECTS commands:
Associate project with current active venv:
setprojectdir <path/to/project/>
Create new project environment:
mkproject
If the environment variable $PROJECT_HOME
(%PROJECT_HOME%
) is set, create a new project directory in PROJECT_HOME
Change into project directory:
cdproject
cd-
- change into the directory you were before running cdproject
Easiest way is to dump all packages from virtualenv
environment and recreate with virtualenvwrapper
:
Here I will cover main
conda
environment management commands only, full list:conda help
andconda env --help
List all environments and locations
conda env list
Activate another environment
conda activate ENVNAME
Reactivate base environment
conda activate base
Create an empty new env
conda env create -n ENVNAME
Clone existing environment
conda create --clone ENVNAME
Create new env from file (.yaml)
conda env create -n ENVNAME --file ENV.yml
Create new env from file (.txt)
conda env create -n ENVNAME --file ENV.txt
Export env to file (.yaml)
conda env export ENVNAME > ENV.yml
Mostly problems are related to incorrectly ENV variables. Some links with help to deal with this:
Sometimes to install additional package is impossible to do via pip because some pre-installed libraries (like MS Studio C++ or mysql/postgresql libraries) needed. So it's better to download and install precompiled packages from here:
Install of .whl package:
When you see this during installing some package with pip:
this means it is required to download and install Microsoft Visual C++ Build Tools:
Download and run installer for Build Tools for Visual Studio 2019
Select checkbox for Build Tools
and click "Install"
It has faster mimicking alternative called
go to > "Tools for Visual Studio 2019"
<-- recommended
<-- required
(Community Edition is OK) or
(with lot of Python plugins)