Python Forum
Cannot get to virtual environment in Jupyter IDE - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cannot get to virtual environment in Jupyter IDE (/thread-29526.html)



Cannot get to virtual environment in Jupyter IDE - ErnestTBass - Sep-07-2020

I am trying to use fbprophet in jupyter notebook in a program for making predictions.

To use it requires python=3.61 which means that I must make a virtual environment
since my base environment uses python 3.8.

I make the virtual environment with no problem. I then active keras-env and that works.

This is all on the command line, new -terminal.

So far everything is fine, but I must make some additional changes or the when I go back to the jupyter notebook
IDE the changes will not be recognized. The IDE has to have these commands.

conda install ipkernel
python -m ipykernel install --user --name=kerasenv.

Now I assume these last two commands above must be run in an active keras-env environment. Nowhere does it say so, but I am just assuming that it must be true.

However, when I leave the command line and go back to the jupyter notebook IDE, it does now have keras-env in the upper right hand corner. So I am assuming I did it right.

I did not!

If I use the drop down down menu and select keras-env it does say that at the upper right hand corner.

However, when I go the first jupyter notebook IDE space and type in:

!python -V

and then execute that one command, I get python 3.85, not 3.61. As I said I want the version of 3.61 because when using keras that is the only python version that works with it a far as I know.

Everything seems, but I am still in the base environment, not the virtual environment.

What am I doing wrong? I believe that I am taking the right steps, but the result is that when in the jupyter notebook IDE, I am still using python 3.85 and not python 3.61. That means I never entered the virtual environment as far as the IDE is concerned. That is what I want to use the keras-env, not my base environment.

My base environment cannot run keras because it has python 3.85.

I have included a series of screenshots that go through the steps that I discussed above.

The only thing that I can think of as being wrong is that my jupyter notebook is being run in Docker container and maybe there is something wrong there.

How I have tried many different Docker containers and it happens in all of them. I have done routine many times before, usually separated by a few months. I must relearn each time.

Any Help appreciated. Thanks in advance.

Respectfully,

ErnestTBass


RE: Cannot get to virtual environment in Jupyter IDE - perfringo - Sep-08-2020

Not help per se but from Python documentation some ideas for further troubleshooting:

Quote:When a virtual environment is active (i.e., the virtual environment’s Python interpreter is running), the attributes sys.prefix and sys.exec_prefix point to the base directory of the virtual environment, whereas sys.base_prefix and sys.base_exec_prefix point to the non-virtual environment Python installation which was used to create the virtual environment. If a virtual environment is not active, then sys.prefix is the same as sys.base_prefix and sys.exec_prefix is the same as sys.base_exec_prefix (they all point to a non-virtual environment Python installation).



RE: Cannot get to virtual environment in Jupyter IDE - Larz60+ - Sep-08-2020

Is the virtual environment activated before you start jupyter notebook?
You can use ipkernal to do this see: https://anbasile.github.io/posts/2017-06-25-jupyter-venv/


RE: Cannot get to virtual environment in Jupyter IDE - ErnestTBass - Sep-08-2020

I will try to activate the virtual environment on the command line before I go to the jupyter notebook IDE.

I will reply only if it fails to work.

Thank for quick response.

ErnestTBass

It did not work. If it's all the same to you, I am going to move this question o th the jupyter notebook form.

I finally have an account on it.

ErnestTBasss


RE: Cannot get to virtual environment in Jupyter IDE - Larz60+ - Sep-08-2020

read the blog at link I supplied


RE: Cannot get to virtual environment in Jupyter IDE - ErnestTBass - Sep-09-2020

I think because I am using a Docker images that some parts of a complete
Ubuntu install are missing. I found that there was no

nb_conda_kernels

installed in the base environment so I installed it. Now a far as the two statements made after the virtual environment is created and installed with python=3.6.

These two statements

conda install ipykernel
python -m ipykernel install --user --name=keras-env
I am not sure whether they are used at all. I can eliminate the first statement by
installing ipykernel when I create and install the virtual environment. I not even sure that the
second one should be used at at all. I have seen examples where is is not used.

I have yet to get it to work, but I think I am close.

I have read your link and it seems to offer no info on this.

ErnestTBass


RE: Cannot get to virtual environment in Jupyter IDE - ErnestTBass - Sep-09-2020

Could you please tell me if I am on the right track with installing nb_conda_kernels?

It seems to work on the Windows 10 version of jupyter notebook, which is part of Anaconda3.

I know that nb_conda_kernels helps in distinguishing between kernels in jupyter notebook. As I said, I think that installing nb_conda_kernels in the base environment solves the issue with Windows Anaconda3 jupyter Notebook.

Just let me know if it is the right approach.

Respectfully,

ErnestTBass