After a long "rake-in" (under both UNIX* and Windows) I decided on the following approach, which has never failed me so far.
n
The basic idea is to install the Anaconda package and create independent virtual environments using the package manager conda.
n
Anaconda checks the compatibility of module versions (including dependencies). This minimizes the chance of breaking Python by simply installing or updating a certain module(s).
n
The algorithm for installing Anaconda and creating a VirtualEnv (independent Python virtual environment):
n
n- Installing Anaconda or Miniconda
n
n
n- Installing on Windows
n- Installing on Linux
n- Installing on macOS
n
n
n- n
We are updating the package manager conda (NOTE: to avoid problems - always run conda from Anaconda Prompt):
n conda update condan
n n- n
Never "touch" Python installed by default in the OS or installed by other software (for example, when installing Oracle Database, a separate Python is installed that will be used by Oracle). By "do not touch" Python, I mean making any changes affecting Python or its modules:
n n
n
n- installing new modules
n- updating Python
n- updating modules
n
n
n- n
Do not install modules in the base virtual environment created by default. Install modules only in those virtual environments that you have explicitly created (see the next point - 5). The base virtual environment is a technical environment created by conda to manage other virtual environments. If you don't want to break all the virtual environments at once, don't touch base.
n n- n
Create an independent virtual environment (VirtualEnv) for each more or less independent Python project. You can additionally create one common environment for common purposes. In this example, I will create a common environment called ml (Machine Leaing) for Python 3.7 and a basic set of modules for working on machine leaing tasks (with Nvidia GPU support):
n conda create --name ml python=3.7 anaconda keras-gpun
n n- n
>n
To run Python / Jupyter / IPython / etc. you can use one of the following monitors from the created VirtualEnv:
n n
n
n- n
launch Anaconda Prompt --> activate the desired software in it. environment (conda activate ) --launch ipython / Jupyter-Notebook
n n- n
use the CMD/shell script to run ipython from the desired vm. environments:
n @echo offn set conda_dir=%USERPROFILE%\Anaconda3n set env_name=%1n if1n if ""%env_name%"""%env_name%""=="""" set env_name=mln set env_dir=%conda_dir%\envs\%env_name%n rem cd % rem cd %env_dir%n call %conda_dir%\Scripts\activate.bat %env_dir%n%env_dir%\Scripts\ipython.exen Example call: `c:\bin\ipy_env.cmd ml37'n
n n- n
use CMD/shell script to run Jupyter-Notebook from the desired wirth. environments:
n @echo offn set env_name=%1n if>n if ""%env_name%""ame%""=="""" set env_name=mln set env_dir=%USERPROFILE%\Anaconda3\envs\%env_name%n rem cd %env_dir%n callir%n call %USERPROFILE%\Anaconda3\Scripts\activate.bat %env_dir%n start cmd.exe /k ""%USERPROFILE%\Anaconda3\envs\%env_name%\Scripts\jupyter-notebook.exe ""n Example calling: `C:\bin/span>\jupyter_env.cmd torch'n
n n- n
for a project in PyCharm, you can specify an existing Conda Environment
n as the Project Interpreter/li>n
n
n- To install a new module, always try to do it in the following sequence:
n
n
n- n
first we always try to find the right module in the default Anaconda repository
n conda search <module_name>n
n n- n
if the module is found - installing it in our VirtualEnv (ml in our example):
n conda install -n mln
n n- n
if if the module is not found, we are trying to find this module in the repository conda-forge (A community-led collection)
n conda search -c conda-forge <module_name>n
n n- n
if the module is found - installing it in our VirtualEnv (ml in our example):
n conda install -c conda-forge -n mln
n n- n
only if the required module is not found either in the original Anaconda repository or in conda-forge - using pip install:
n conda activate mln pip installn
n n
n
n- n
to update the module, use the package manager conda:
n conda update -n mln
n n
n
n
Useful links:
n
n- Conda Tutorial
n- Conda Cheat Sheet
n