user12450767
user12450767

Reputation:

Command line doesn't use python from conda environment even though it's active, maybe problem in .bash_profile?

I've activated a conda environment and see it's active, but when I type "which python", I get "/usr/local/bin/python", instead of the python of the environment. And I get Import errors for packages I know are installed. I think the problem might be in .bash_profile, but I don't know how to fix it.

I'm working on macOS.

How do I make sure that the command line uses the environment's python?

Upvotes: 4

Views: 2492

Answers (1)

Loïc G.
Loïc G.

Reputation: 3157

Your PATH environment variable probably doesn't contains the path to the python environment from conda.

Running export PATH="/path/to/conda/bin:$PATH" or adding it to your ~/.bashrc would probably solve your issue.

But there is a conda command that does it for you: conda init bash

EDIT:

As mentionned in comment by @cel and also in the conda docs : It's better to use conda init than explicitely editing PATH by your own.

This will allow conda being less disruptive regarding other programs on your system.

conda init will add some more commands in your shell rc file to only modify PATH when a conda environment is activated.

Upvotes: 3

Related Questions