Install Jupyterlab in python virtual env in FreeBSD 13

Hi All,

I am trying to install Jupyterlab on freebsd 13 using python virtual environment. Initially I ran into trouble. But searching online I was able to install it using;
Code:
export C_INCLUDE_PATH=/usr/local/include/:${C_INCLUDE_PATH}
export CPLUS_INCLUDE_PATH=/usr/local/include/:${CPLUS_INCLUDE_PATH}

But after Installation at launch I get another error:
Code:
(.venvML) [michael@schroter ~]$ jupyter lab
Traceback (most recent call last):
  File "/usr/home/michael/.venvML/bin/jupyter-lab", line 5, in <module>
    from jupyterlab.labapp import main
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyterlab/labapp.py", line 13, in <module>
    from jupyter_server.serverapp import flags
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyter_server/serverapp.py", line 73, in <module>
    from jupyter_server.services.kernels.kernelmanager import (
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyter_server/services/kernels/kernelmanager.py", line 15, in <module>
    from jupyter_client.multikernelmanager import AsyncMultiKernelManager
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyter_client/__init__.py", line 6, in <module>
    from .asynchronous import AsyncKernelClient  # noqa
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyter_client/asynchronous/__init__.py", line 1, in <module>
    from .client import AsyncKernelClient  # noqa
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyter_client/asynchronous/client.py", line 6, in <module>
    from jupyter_client.channels import HBChannel
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/jupyter_client/channels.py", line 12, in <module>
    import zmq.asyncio
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/zmq/__init__.py", line 61, in <module>
    _load_libzmq()
  File "/usr/home/michael/.venvML/lib/python3.8/site-packages/zmq/__init__.py", line 36, in _load_libzmq
    from . import libzmq
ImportError: /usr/home/michael/.venvML/lib/python3.8/site-packages/zmq/libzmq.cpython-38.so: Undefined symbol "_Ux86_64_getcontext"

Would you be able to help me in this matter please? I have libunwind already installed using pkg.
Thanks & Best Regards
Schroter Michael
 
Hi, I ran into the same issue. I solved it by installing libzmq using pkg and reinstalling the pyzmq library. This prevents pyzmq compiling its own version of libzmq if it is not found on the system.


pkg install libzmq4
pip install --upgrade --no-deps --force-reinstall --no-binary pyzmq pyzmq
 
Found this in 2024 and thought I'd post my solution for future searchers. In linux and macos, I just use miniconda these days. That's not really an option ATM on freebsd. However, what I used to do before miniconda, still works in freebsd and isn't difficult to implement in clean install (FreeBSD 14 tested, used previously 12+).

Note: added correction for libzmq4

Code:
pkg install libzmq4

Install pyenv and update .bashrc:

Code:
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc

Reenter shell, install python with tcl/tk support, and select it as the python version to use

Code:
pyenv install -l

PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/include' --with-tcltk-libs='-L/usr/local/lib -ltcl8.6 -ltk8.6'" pyenv install 3.9.18

pyenv global 3.9.18

Reenter shell, confirm it's your desired python version, and install jupyterlab to test

Code:
python --version
Python 3.9.18

python -m venv test
source test/bin/activate
pip install --upgrade pip
pip install --upgrade --no-deps --force-reinstall --no-cache --no-binary pyzmq pyzmq
pip install jupyterlab

jupyterlab

Celebrate!
 
Last edited:
Back
Top