I have encountered an strange issue today, and want to record it in case I met it again or others who find it is helpful.
intro: anaconda Link to heading
It is so famous that almost everyone that code with python knows it. (if you don’t know that, please search and get familiar with it, very helpful) it provides python version control so that you don’t worries about install so many versions of python and mess up system.
intro: venv Link to heading
After some version of python3 it became a standard library of python. it is also important to use venv to keep libraries that installed not interference with each other. Different version of libraries can cause conflicts so that after enable the virtual environment, it provides a sandbox like folder so that you can install whatever you need and don’t interfere others.
conda python version and venv activate the same time Link to heading
When activate python in conda and activating virtural environment at the same time, you may find it doesn’t use the desired python version. For example, you have a base version python 3.7 and you want to use python 3.6 and you do activate conda python 3.6. when you run say pip install xxx, it will automatically use python 3.7 which is default.
So in this case, we have to input python3.6 -m pip install xxx to explicitly use python3.6.
To tell the turth, I encountered similiar situation even not using pip. So as far as I think, to explicitly state python version (python3.6 xxx) is the best practice.
jupyter and venv Link to heading
jupyter is default in conda.
For some project that has its own environment, you want to start jupyter notebook ‘inside’ the project. Instead, you probably see
[I 16:17:52.275 NotebookApp] JupyterLab extension loaded from /home/<your_username>/anaconda3/lib/python3.7/site-packages/jupyterlab
The result of above is your environment suddenly ‘disapper’!
Try two things:
- see if the venv the same with your project(or just you forget to activate venv)
- do what Angelo Basile does
- switch between
jupyter notebookandjupyter-notebookto see which one actually start from your venv folder
TBC Link to heading
There might be other situation conda venv and other application together messed up your day.