Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block package installations to conda base environment

Tags:

python

pip

conda

I'm currently using miniconda and I want to prevent myself and other users of my machine from installing anything into the base environment. This is because I want users to be creating virtual environments and installing stuff there. I also don't want my base environment to get bloated.

Is there anyway to do this? I use both conda and pip so I imagine I need to somehow block both of those.

like image 622
Johnny Metz Avatar asked Jul 29 '18 04:07

Johnny Metz


People also ask

Should I install packages in conda base?

Avoid installing packages into your base Conda environment Conda has a default environment called base that include a Python installation and some core system libraries and dependencies of Conda. It is a “best practice” to avoid installing additional packages into your base software environment.

How do I stop conda installation?

To exit the virtual environment, use the command conda deactivate . If you run conda info --envs again, there is no * in front of env_name .

How do I install packages in anaconda base environment?

Go to Environments tab just below the Home tab and from there we can check what all packages are installed and what is not. It is very easy to install any package through anaconda navigator, simply search the required package, select package and click on apply to install it.

How do I install packages with conda?

There are two ways to install packages with conda. 1️⃣ From inside an active environment. 2️⃣ From your default shell. The latter requires you to point to the environment you want to install packages in using the same flag (--name or --prefix) that you used to create your environment with.

How do I create a base environment in conda?

On installation, conda creates a base environment. However, you can also create your own base environment with packages you frequently use. The - -clone option will create a clone (or snapshot) of the environment, If you need to reproduce an environment across computers with the same operating system, you can generate a spec list.

What does the conda activate base setting do?

This setting controls whether or not conda activates your base environment when it first starts up. You'll have the conda command available either way, but without activating the environment, none of the other programs in the environment will be available until the environment is activated with conda activate base.

What is the use of a Conda-pack?

Conda-pack is a command line tool that archives a conda environment, which includes all the binaries of the packages installed in the environment. This is useful when you want to reproduce an environment with limited or no internet access. All the previous methods download packages from their respective repositories to create an environment.


1 Answers

One option would be to change the write permissions on the directories pip and conda install packages to for the base environments. These locations vary based on your distribution, but you can check by using something like python -c "import setuptools; print(setuptools.__file__)". The parent directory to setuputils will be where the packages get installed by default. Run chmod -w <packages dir> to remove write permissions. You can always add them back with chmod +w <packages dir> later, but while they're disabled this should keep you from installing packages there by accident. Unless you haphazardly install packages with sudo, that is...

like image 142
augray Avatar answered Oct 14 '22 14:10

augray