Pip Installing Dependencies Into Conda Envs
I prefer to use Conda because once installed it works essentially the same everywhere. Including Windows.
Step 1: Create a Virtual Environment
conda create -n credible python=3.10
After agreeing to install some dependencies, it places them in an out-of-the way location. Here's where they are on my work, personal laptops, and a 2018-era Windows laptop I sometimes test on:
Get the list of current envs:
$ conda env list base * /Users/drg/opt/miniconda3 credible /Users/drg/opt/miniconda3/envs/credible system /Users/drg/opt/miniconda3/envs/system that /Users/drg/opt/miniconda3/envs/that just /Users/drg/opt/miniconda3/envs/just works /Users/drg/opt/miniconda3/envs/works everywhere /Users/drg/opt/miniconda3/envs/everywhere
Step 2: Activate a Virtual Environment
conda activate credible
This prefixes the CLI shell with
(credible), exactly like
Step 3: Install Dependencies Using Pip Into a Conda Env
Just like many any other virtual environments for Python, use pip to install/uninstall dependencies
(credible) python -m pip install typer
That's right. I'm using pip to manage packages in a conda env. Conda works great with pip. Conda has worked great with pip for years.
Because I know you have them.
1. What about conda install for dependencies?
I rarely use
conda install on MacOS or Linux. On Windows,
conda install is sometimes useful because it handles non-python binaries that otherwise require Docker, Chocolately, or other tools.
2. Why not pyenv-win instead of conda?
- I always struggled to get pyenv-win to work on Windows
- Didn't handle non-python binaries well, requiring use of Chocalatey
- Conda just works
3. Did you ever teach classes with Conda?
Yes. Conda was awesome when I used to teach. Conda is a universal installation system that works for everyone regardless of operating system. Once people got it installed we got to teaching instead of dealing with setup issues.
4. What about Docker instead of Conda?
My classes focused more on teaching Python and Django rather than Docker. Docker is a whole different world.
5. What does Audrey use?
Audrey uses pyenv and loves it. Taught people to use pyenv and pyenv-win.
- 2022-03-12 Suggested by David R. Pugh: Changed to use
python -m pipto ensure the dependency is installed on the right place.
Tags: python conda MacOS Windows Linux