# Incorrect package versions for environment in Jupyter

**URL:** <https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183>\
**Category:** Packages & Environments\
**Created:** [November 22, 2021, 7:00pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183 "2021-11-22T19:00:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Beck](https://avatars.discourse-cdn.com/v4/letter/m/80bc00/32.png) [@Mike\_Beck](https://forum.anaconda.com/u/Mike_Beck)\
**Post date:** [November 22, 2021, 7:00pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/1 "2021-11-22T19:00:29Z")

</div>

I created an environment using the Anaconda prompt with a few packages downgraded to match a previous run of a Jupyter notebook. I then used ipykernel to make this environment a selectable kernel in Jupyter.

When I check the package versions for the environment in Anaconda Navigator, they are correct, but with the kernel selected in my Jupyter notebook, when I run a cell that prints the package versions, it shows the versions in the base environment.

I assume this means my Jupyter notebook is using the package versions from the base environment - if so, what have I missed in my process to make what I see in Navigator match what I get in my notebook?

---

<div class="post-metadata">

**Author:** ![MARTIN\_DURANT](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/martin_durant/32/67_2.png) [@MARTIN\_DURANT](https://forum.anaconda.com/u/MARTIN_DURANT)\
**Post date:** [November 22, 2021, 7:34pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/2 "2021-11-22T19:34:55Z")

</div>

> I run a cell that prints the package versions

It will likely depend on how exactly you do this.

One simple way to ensure you run pip from the same environment as the current python might look like

```auto
import pip
pip.main(["list"])

```

If you want _conda’s_ opinion on packages, then there are a few things at play. Typically, you do not have conda (he application) installed in an environment, it only lives in base. That’s fine when you run from a command line, as an environment will be “activated”. Navigator, in contrast, knows how to tell conda which environment it wants to work on without activating. So to call conda from within a kernel not in the currently active environment, you should explicitly pass the environment:

```auto
!conda list -n myenv

```

---

<div class="post-metadata">

**Author:** ![Mike\_Beck](https://avatars.discourse-cdn.com/v4/letter/m/80bc00/32.png) [@Mike\_Beck](https://forum.anaconda.com/u/Mike_Beck)\
**Post date:** [November 22, 2021, 7:45pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/3 "2021-11-22T19:45:07Z")

</div>

Thank you for the info! I was actually only running a few print commands like this:

print(f"Scikit-Learn version {sklearn. **version** }") (The post formatting is removing the underscores around “version”, but you get what I mean)

When I try your first suggestion, I get the same results as my print statements for those packages. When I run the 2nd with my environment name, I see my intended package versions instead. But that appears to mean that I’m not actually running in my environment, even though I’ve selected that kernel. I guess my real question now is how do I run in that environment if selecting that kernel isn’t enough?

Appreciate your help

---

<div class="post-metadata">

**Author:** ![MARTIN\_DURANT](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/martin_durant/32/67_2.png) [@MARTIN\_DURANT](https://forum.anaconda.com/u/MARTIN_DURANT)\
**Post date:** [November 22, 2021, 7:58pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/4 "2021-11-22T19:58:05Z")

</div>

You should check the value of `sys.executable`, to see which python is running. It should be like “…/conda/envs/myenv/bin/python”. This is in posix format, it will look a little different for Windows, but “myenv” should be in there.

---

<div class="post-metadata">

**Author:** ![Mike\_Beck](https://avatars.discourse-cdn.com/v4/letter/m/80bc00/32.png) [@Mike\_Beck](https://forum.anaconda.com/u/Mike_Beck)\
**Post date:** [November 22, 2021, 8:07pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/5 "2021-11-22T20:07:00Z")

</div>

Hmm, yes, that gives me the location “…\ProgramData\Anaconda3\python.exe”. That Anaconda3 folder contains a subfolder called “envs” which has the environment I’ve created, but apparently the python.exe that’s sitting in there isn’t being used. Not sure why

---

<div class="post-metadata">

**Author:** ![MARTIN\_DURANT](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/martin_durant/32/67_2.png) [@MARTIN\_DURANT](https://forum.anaconda.com/u/MARTIN_DURANT)\
**Post date:** [November 22, 2021, 8:28pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/6 "2021-11-22T20:28:22Z")

</div>

Yep sorry, beyond suggestions here. I’m not sure how ipykernel finds the python it wants to execute. Perhaps you need `nb_conda_kernels`

---

<div class="post-metadata">

**Author:** ![matt](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/matt/32/38_2.png) [@matt](https://forum.anaconda.com/u/matt)\
**Post date:** [November 22, 2021, 11:27pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/7 "2021-11-22T23:27:23Z")

</div>

> [@Mike\_Beck](#):
>
> I then used ipykernel to make this environment a selectable kernel in Jupyter.

Hi Mike, and welcome! I have just tried the steps in [this article](https://medium.com/@nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084) and was successful. I suspect that maybe you executed the command `python -m ipykernel install --user --name=my-env` from the `base` interpreter, rather than from your conda environment.

On my system, I have my `base` interpreter, and then another environment called `my-env`. I ran the command above, once from within my environment (i.e. after `conda activate my-env`) and once from within the `base` environment.

In the figure below, `my-env` was created from the conda environment, `my-other-env` was created from the `base` environment. Despite having custom names as Jupyter kernels, they are each associated with the version of python used when running the `ipykernel` command.

 ![image](https://europe1.discourse-cdn.com/anaconda/original/1X/cd7f8f7cd61e5e7ae10ab94c45255b14fdcd2cc7.png)

I think you can explicitly pass the path to `python.exe` on Windows to ensure this behavior, but I would first confirm you have used `conda activate my-env` first in either case.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Mike\_Beck](https://avatars.discourse-cdn.com/v4/letter/m/80bc00/32.png) [@Mike\_Beck](https://forum.anaconda.com/u/Mike_Beck)\
**Post date:** [November 23, 2021, 1:55pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/8 "2021-11-23T13:55:25Z")

</div>

Thank you! This definitely appears to have addressed that issue. It looks like I have a bit more work to do on the environment itself (getting an error when I try to run the very basic command “import pandas as pd” lol), but the package list has all the right versions now. Really appreciate the help!

---

<div class="post-metadata">

**Author:** ![matt](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/matt/32/38_2.png) [@matt](https://forum.anaconda.com/u/matt)\
**Post date:** [November 23, 2021, 2:17pm UTC](https://forum.anaconda.com/t/incorrect-package-versions-for-environment-in-jupyter/183/9 "2021-11-23T14:17:10Z")

</div>

Glad I could help!

Similar to @MARTIN_DURANT 's suggestion above, you should be able to install dependencies from within that kernel using

```auto
!conda install pandas

```
