|
1 | 1 | # Extra material about isolated environments |
2 | 2 |
|
| 3 | +## Virtual environment - venv & virtualenv |
| 4 | + |
| 5 | +With this tool you can download and install with ``pip`` from the [PyPI repository](https://pypi.org/) |
| 6 | + |
| 7 | +:::{note} |
| 8 | + |
| 9 | + - You can use "pip list" on the command line (after loading the python module) to see which packages are available and which versions. |
| 10 | + - Some packages may be inherited from the modules you have loaded |
| 11 | + - You can do ``pip list --local`` to see what is installed by you in the environment. |
| 12 | + - Some IDE:s like Spyder may only find those "local" packages |
| 13 | + - To save space, you should load any other Python modules you will need that are system installed before installing your own packages! Remember to choose ones that are compatible with the Python version you picked! |
| 14 | + - ``--system-site-packages`` includes the packages already installed in the loaded python module. |
| 15 | + - The ``--no-cache-dir"`` option is required to **avoid it from reusing earlier installations from the same user in a different environment**. |
| 16 | + - The ``--no-build-isolation`` is to make sure that it uses the loaded modules from the module system when **building any Cython libraries**. |
| 17 | +::: |
| 18 | + |
| 19 | +## Conda |
| 20 | + |
| 21 | +- [Conda](https://anaconda.org/anaconda/conda) is an installer of packages but also bigger toolkits and is useful also for R packages and C/C++ installations. |
| 22 | + |
| 23 | +:::{warning} |
| 24 | + |
| 25 | + Drawbacks |
| 26 | + |
| 27 | + - Conda cannot use already install packages from the Python modules and libraries already installed, and hence installs them anyway |
| 28 | + - Conda is therefore known for creating **many** *small* files. Your disk space is not only limited in GB, but also in number of files (typically ``300000`` in $HOME). |
| 29 | + - Check your disk usage and quota limit |
| 30 | + - Do a ``conda clean -a`` once in a while to remove unused and unnecessary files |
| 31 | +::: |
| 32 | + |
| 33 | +:::{tip} |
| 34 | + |
| 35 | + - The conda environments including many small files are by default stored in ``~/.conda`` folder that is in your $HOME directory with limited storage. |
| 36 | + - Move your ``.conda`` directory to your project folder and make a soft link to it from ``$HOME`` |
| 37 | + - Do the following (``mkdir -p`` ignores error output and will not recreate another folder if it already exists): |
| 38 | + - (replace what is inside ``<>`` with relevant path) |
| 39 | + |
| 40 | + - Solution 1 |
| 41 | + |
| 42 | + This works nicely if you have several projects. Then you can change these variables according to what you are currently working with. |
| 43 | + |
| 44 | + ```bash |
| 45 | + |
| 46 | + export CONDA_ENVS_PATH="path/to/your/project/(subdir)" |
| 47 | + export CONDA_PKG_DIRS="path/to/your/project/(subdir)" |
| 48 | + mamba create --prefix=$CONDA_ENVS_PATH/<conda env name> |
| 49 | + ``` |
| 50 | + |
| 51 | + - Solution 2 |
| 52 | + |
| 53 | + - This may not be a good idea if you have several projects. |
| 54 | + |
| 55 | + ```bash |
| 56 | +
|
| 57 | + mkdir -p ~/.conda |
| 58 | + mv ~/.conda /<path-to-project-folder>/<username>/ |
| 59 | + ln -s /<path-to-project-folder>/<username>/.conda ~/.conda |
| 60 | + ``` |
| 61 | +::: |
| 62 | + |
3 | 63 | ## Workflow ``venv`` |
4 | 64 |
|
5 | 65 | 1. Start from a Python version you would like to use (load the module): |
|
0 commit comments