1

I am working on machine learning project where dependency issue are a big headache. Specifically, many package could only be installed by pip, not conda. so i need a way to install them to a environment, seperated from other environment.

First, i "conda create --name myenv", this way i create a env. Then, "conda install xxx" will simply install it to your current env, however, some of them are available by "pip install". So instead i try "conda install pip" and then "pip install xxx"

I wonder will this help me install xxx to my current env so that other envs can not see this?

if not, how could i do that?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
CHYjeremy
  • 7
  • 2

1 Answers1

2

To install a package only in a specific Conda environment and isolate it from other environments, you can use the following approach:

  1. Create a new Conda environment: If you haven't already, create a new Conda environment using the following command:

    conda create --name myenv

  2. Activate the new environment: Activate the newly created environment using:

    conda activate myenv

  3. Install pip in the Conda environment:

    conda install pip

  4. Install packages using pip: Now that you have pip installed in your environment, you can use pip to install packages specific to this environment. For example: pip install xxx

By doing this, the package "xxx" will be installed only within the "myenv" Conda environment and will not affect other environments on your system.

  • thanks chetan, but have you met https://stackoverflow.com/a/43729857/10250051. this? what do you think is the difference when you add the path to pip in your fourth step? – CHYjeremy Aug 06 '23 at 04:16
  • 1
    @CHYjeremy that shouldn't matter if the virtual environment is sourced using the activate script. Activating the virtual environment updates the `PATH` environment variable in the current shell, which will add the `bin` directory of the virtual environment to `PATH` at a high priority. Adding the full path is more explicit, but the `pip` executable should resolve to that same path if the virtual environment has already been sourced. In unix you could confirm by running `which pip` – flakes Aug 06 '23 at 04:58