Pipenv is great. But it is not a perfect solution. Besides, sometimes it is convenient if we can use anaconda to manage some libraries that does not work well with pip
.
Luckily, it is possible to take the best of two worlds.
The easiest way to do it is via pyenv installer.
We can now use pyenv to manage python and anaconda versions. For example,
pyenv install anaconda3-5.3.1
pyenv global anaconda3-5.3.1
Now you can install packages that are managed by anaconda.
As an example, if you want to install Tkinter, you can run
conda install tk
Now we can install pipenv using the pip of conda:
pip install pipenv
Before using pipenv to install packages, you need to set up pipenv to use the Python distribution of your anaconda environment. [ref]
$ cd your-repo
$ conda_python=$(python -c 'import sys; print(sys.executable);')
$ pipenv --python=$conda_python --site-packages
Finally, if you have a Pipfile
in your repo directory, you can install packages by pipenv install
.
You can also install new packages.
Let me list some pitfalls that I falled into using this approach.
If you installed some libraries but the program still return you error messages like
usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.11' not found
you might need to manually add libraries installed by anaconda to your PATH:
export LD_LIBRARY_PATH=/home/USERNAME/.pyenv/versions/anaconda3-5.2.0/lib:$LD_LIBRARY_PATH
You can check conda installation directory by conda info
Currently, the default JupyterLab shipped with anaconda installation does not recognize packages installed by pipenv
.
Therefore, you need to install JupyterLab via pipenv: pipenv install --dev jupyterlab jupytext
(I did not check for Jupyter Notebook)
Written on September 2nd , 2019 by Hanezu