NixOS python311 langchain Package Support (pkgs.python311Packages.langchain)

Problem description:
NixOS Errors on Package Support for Python 311 langchain. Use Case, Document Vector without using OpenAI APIs, pure python. No working example of this could be found using search on replit, they all use APIs.

Expected behavior:
System Ready

Actual behavior:

~/langchainsupport$ 
Detected change in environment, reloading shell...
nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines
instantiated 'YAML-Tiny-1.73.tar.gz' -> '/nix/store/0j04z434xl9829mx8rvaxnk9v3kvibw5-YAML-Tiny-1.73.tar.gz.drv'
instantiated 'perl5.36.0-YAML-Tiny-1.73' -> '/nix/store/cr1gv08fii6jmm6yysk4w5pa50g53q53-perl5.36.0-YAML-Tiny-1.73.drv'
instantiated 'po4a-0.62.tar.gz' -> '/nix/store/ys8blq95nqqw90v9189mwpz1kmxl72j1-po4a-0.62.tar.gz.drv'
instantiated 'perl5.36.0-po4a-0.62' -> '/nix/store/c0d3xl6fzhyd2k8ldahqm2vkk56zw3hn-perl5.36.0-po4a-0.62.drv'
instantiated 'util-linux-2.38.1.tar.xz' -> '/nix/store/c8y7381wbz9gyg737knyf2f9pi354qwq-util-linux-2.38.1.tar.xz.drv'
instantiated 'util-linux-2.38.1' -> '/nix/store/27nxqn5jj7hw7142xipqb5ckfgl6m6q3-util-linux-2.38.1.drv'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/sympy/default.nix'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/mpmath/default.nix'
instantiated 'CVE-2021-29063.patch' -> '/nix/store/1p9ljzvsw6h5nsj0q9g85rsks8vdf0n4-CVE-2021-29063.patch.drv'
instantiated 'mpmath-1.2.1.tar.gz' -> '/nix/store/fphss2hbg77rrxszhi9mb4lg2x29zf3d-mpmath-1.2.1.tar.gz.drv'
instantiated 'python3.11-mpmath-1.2.1' -> '/nix/store/kz933nw77a7552873hl1fyd051csaybd-python3.11-mpmath-1.2.1.drv'
instantiated 'sympy-1.11.1.tar.gz' -> '/nix/store/1zymkbjvvqac5d0nyyawhwb5armxy5g2-sympy-1.11.1.tar.gz.drv'
instantiated 'python3.11-sympy-1.11.1' -> '/nix/store/ypswa3v5x0pkmvv9i5wvjdk8rq3pdvl5-python3.11-sympy-1.11.1.drv'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/future/default.nix'
instantiated 'future-0.18.3.tar.gz' -> '/nix/store/sba3xg23yn9ah21wj7ag5v1ld7j89dab-future-0.18.3.tar.gz.drv'
instantiated 'python3.11-future-0.18.3' -> '/nix/store/8xsa63fmm6macszdfrbbwk9qbcwkdzrv-python3.11-future-0.18.3.drv'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/tensorboard/default.nix'
error: tensorboard-2.11.0 not supported for interpreter python3.11
(use '--show-trace' to show detailed location information)

Steps to reproduce:
.replit

entrypoint = "main.py"
modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]

[nix]
channel = "stable-23_05"

[deployment]
run = ["sh", "-c", "python3 main.py"]

replit.nix

{ pkgs }: {
  deps = [
    pkgs.python311Packages.langchain
  ];
}

Bug appears at this link:
https://replit.com/@PeterCampbell6/langchainsupport

Browser:
OS:
Device (Android, iOS, n/a leave blank):
Plan (Free, Hacker, Pro Plan):
Free

I really want replit to work :crossed_fingers:

I wanted to pro upgrade and not have to keep using a vm.

This was a bug in nixpkgs that has been fixed, but the Nix channels are outdated because replit stores a cached copy of nixpkgs which it has to update manually. As a workaround, install langchain through the “Packages” tool.
Alternatively, you could try and add this to replit.nix:

  env = {
    PYTHONPATH = [ pkgs.python310Packages.langchain /*the dependencies of langchain here*/ ]
  }

No Support for pkgs.python311Packages.langchain then?

Do I have to manually specify the dependency tree for this configuration to work?

replit.nix
edited to add required dependencies for installation

{ pkgs }: {
  deps = [
    pkgs.python311Packages.langchain
    pkgs.python311Packages.pandas
    pkgs.python311Packages.libffi
    pkgs.python311Packages.polars
  ];

  env = {
    PYTHONPATH = [
        pkgs.python311Packages.langchain
        pkgs.python311Full
        pkgs.python311Packages.requests
        pkgs.python311Packages.tqdm
        pkgs.python311Packages.jsonschema_3
        pkgs.python311Packages.jsonschema
        pkgs.python311Packages.jsonnet
        pkgs.python311Packages.pyyaml
        pkgs.python311Packages.tabulate
        pkgs.python311Packages.tensorboard
    ];
  };
}
nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines
instantiated 'YAML-Tiny-1.73.tar.gz' -> '/nix/store/0j04z434xl9829mx8rvaxnk9v3kvibw5-YAML-Tiny-1.73.tar.gz.drv'
instantiated 'perl5.36.0-YAML-Tiny-1.73' -> '/nix/store/cr1gv08fii6jmm6yysk4w5pa50g53q53-perl5.36.0-YAML-Tiny-1.73.drv'
instantiated 'po4a-0.62.tar.gz' -> '/nix/store/ys8blq95nqqw90v9189mwpz1kmxl72j1-po4a-0.62.tar.gz.drv'
instantiated 'perl5.36.0-po4a-0.62' -> '/nix/store/c0d3xl6fzhyd2k8ldahqm2vkk56zw3hn-perl5.36.0-po4a-0.62.drv'
instantiated 'util-linux-2.38.1.tar.xz' -> '/nix/store/c8y7381wbz9gyg737knyf2f9pi354qwq-util-linux-2.38.1.tar.xz.drv'
instantiated 'util-linux-2.38.1' -> '/nix/store/27nxqn5jj7hw7142xipqb5ckfgl6m6q3-util-linux-2.38.1.drv'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/sympy/default.nix'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/mpmath/default.nix'
instantiated 'CVE-2021-29063.patch' -> '/nix/store/1p9ljzvsw6h5nsj0q9g85rsks8vdf0n4-CVE-2021-29063.patch.drv'
instantiated 'mpmath-1.2.1.tar.gz' -> '/nix/store/fphss2hbg77rrxszhi9mb4lg2x29zf3d-mpmath-1.2.1.tar.gz.drv'
instantiated 'python3.11-mpmath-1.2.1' -> '/nix/store/kz933nw77a7552873hl1fyd051csaybd-python3.11-mpmath-1.2.1.drv'
instantiated 'sympy-1.11.1.tar.gz' -> '/nix/store/1zymkbjvvqac5d0nyyawhwb5armxy5g2-sympy-1.11.1.tar.gz.drv'
instantiated 'python3.11-sympy-1.11.1' -> '/nix/store/ypswa3v5x0pkmvv9i5wvjdk8rq3pdvl5-python3.11-sympy-1.11.1.drv'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/future/default.nix'
instantiated 'future-0.18.3.tar.gz' -> '/nix/store/sba3xg23yn9ah21wj7ag5v1ld7j89dab-future-0.18.3.tar.gz.drv'
instantiated 'python3.11-future-0.18.3' -> '/nix/store/8xsa63fmm6macszdfrbbwk9qbcwkdzrv-python3.11-future-0.18.3.drv'
evaluating file '/nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/development/python-modules/tensorboard/default.nix'
error: tensorboard-2.11.0 not supported for interpreter python3.11
(use '--show-trace' to show detailed location information)

Do I need to do this in a virtual env using venv? is that the problem?

I hadn’t tested the replit.nix part, and I remembered a way to prevent listing all the dependencies. Here’s a solution:

  env = {
    PYTHONPATH = "${pkgs.python311.withPackages (p: [p.numpy p.numexpr])}/lib/python3.11/site-packages:${pkgs.python310.withPackages (p: [p.langchain])}/lib/python3.10/site-packages";
  };

when you’re doing this sort of workaround, if there’s an internal import error with a package, add that package to the python311.withPackages callback return value array, as I’ve done with numpy etc. (so it uses the correct native module for 3.11).

1 Like

Working Here
But Forking this or trying to reproduce fails
https://replit.com/@PeterCampbell6/PythonEnv

Can’t figure out what is special about this one and why when I try to fork this replit it crashes as soon as I try to load it

I am going to try to implement your instructions in a fresh replit.

Only issue is, it requires me to reinstall when ever I enter the virtual environment

Was able to get it to fork, when I tried to create it with the same name it wasn’t working. But the forked replit isn’t behaving the same.

https://replit.com/@PeterCampbell6/langchainsupport2#.replit

Working on https://replit.com/@PeterCampbell6/langchainsupport3

Kind of stuck as everything seems to indicate a successful installation in the virtual python env but it keeps looking at the site packages.

commands

pip config list

modified
/nix/store/crvjb24kkwvcnrhjyk91p9w4bbh9ahf6-pip.conf

—start of file—
[global]
user = yes
disable-pip-version-check = no modified yes
index-url = https://package-proxy.replit.com/pypi/simple/

[install]
removed use-feature = content-addressable-pool
content-addressable-pool-symlink = yes

----end of file----

replit.nix

{ pkgs }: {
    deps = [
        pkgs.vim
        pkgs.python311Full
    	pkgs.python311Packages.pyyaml
    	pkgs.python311Packages.sqlalchemy
    	pkgs.python311Packages.aiohttp
    	pkgs.python311Packages.dataclasses-json
    	pkgs.python311Packages.numexpr
    	pkgs.python311Packages.pydantic
    	pkgs.python311Packages.requests
    	pkgs.python311Packages.tenacity
    	pkgs.python311Packages.attrs
    	pkgs.python311Packages.charset-normalizer
    	pkgs.python311Packages.multidict
    	pkgs.python311Packages.async-timeout
    	pkgs.python311Packages.yarl
    	pkgs.python311Packages.frozenlist
    	pkgs.python311Packages.aiosignal
    	pkgs.python311Packages.marshmallow
    	pkgs.python311Packages.typing-inspect
    	pkgs.python311Packages.typing-extensions
    	pkgs.python311Packages.idna
    	pkgs.python311Packages.urllib3
    	pkgs.python311Packages.certifi
    	pkgs.python311Packages.greenlet
    	pkgs.python311Packages.packaging
    	pkgs.python311Packages.mypy-extensions
        pkgs.python311Packages.jsons
        pkgs.python311Packages.pip
        pkgs.python311Packages.numpy
        pkgs.python311Packages.pandas
        pkgs.python311Packages.polars
        pkgs.python311Packages.matplotlib
        pkgs.python311Packages.jinja2
        pkgs.python311Packages.jinja2-time
        pkgs.python311Packages.sqlite-utils
        pkgs.python311Packages.duckdb
        pkgs.python311Packages.duckdb-engine
        pkgs.python311Packages.jupyter
        pkgs.duckdb
        pkgs.wget
        pkgs.unzip
    ];
}

to get langchain to work with python 3.11 on what’s currently the Beta Python template while we wait for replit’s Nix index to update, all you need to do is edit your replit.nix file like this

{pkgs}: {
  env = {
    PYTHONPATH = pkgs.lib.concatMapStringsSep ":" (e: "${e}/${e.sitePackages}") [(pkgs.python311.withPackages (p: [p.numpy p.numexpr])) (pkgs.python310.withPackages (p: [p.langchain]))];
  };
}

(same as what I previously sent, but cleaner)
and change python-3.10… in the .replit file to python-3.11:v2-20230831-f4ed402

2 Likes

Yes, second part I discovered but the env is giving me issues with the venv in python with the bash shell

Difficulty with learning how replit, nix, all are setup on these servers to get consistent results.

When you don’t have complete control, you have to work with the scheme implemented.

@UMARismyname open question: why 3.10? Doesn’t seem to be be needed. Is it?

Tested this (above), it still isn’t searching the venv for the alternate packages installed in the virtual environment. I can’t get venv to function correctly yet, haven’t lost hope.

Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.0.1
    Not uninstalling pip at /nix/store/yi6scf22zanz3c3jcq60dh94i12fn1d1-python3.11-pip-23.0.1/lib/python3.11/site-packages, outside environment /home/runner/langchainsupport3/virt
    Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-22.3.1

[notice] A new release of pip is available: 23.0.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
(virt) ~/langchainsupport3$ pip -V
pip 23.0.1 from /nix/store/yi6scf22zanz3c3jcq60dh94i12fn1d1-python3.11-pip-23.0.1/lib/python3.11/site-packages/pip (python 3.11)

This is where I am @UMARismyname

Need to modify $PYTHONPATH being used in the venv to use modified path for pip and langchain

#pip config list to locate:
PIP_CONFIG_FILE=/nix/store/crvjb24kkwvcnrhjyk91p9w4bbh9ahf6-pip.conf

#cp above to .config directory, update it to be venv compliant
export PIP_CONFIG_FILE=/home/runner/langchainsupport3/.config/pip.conf
#Backup PYTHONPATH
export OLD_PYTHONPATH=$PYTHONPATH
#Update the PYTHONPATH
export PYTHONPATH=/home/runner/langchainsupport3/virt/lib/python3.11/site-packages/
#Install pip Upgrade Again. venv style
python -m pip install -U pip

Next Step…Rewrite the venv bash scripts to automate this process

(virt) ~/langchainsupport3$ pip -V
pip 23.2.1 from /home/runner/langchainsupport3/virt/lib/python3.11/site-packages/pip (python 3.11)

(virt) ~/langchainsupport3$ python -V
Python 3.11.3

Both venv and non-venv packages are working and pip shows the updated version in this test.

Looks close…only wish I could have figured this out earlier … but challenges learning is great! @UMARismyname Thanks for your great patience and support!

1 Like

@UMARismyname Yoda, update for all and you observers…Everything looks normal now, stuff is set in venv, untouched outside of it, then restored again once deactivated.

I think we have this one solved.

Outside of venv:

~/langchainsupport3$ pip -V
pip 23.0.1 from /nix/store/yi6scf22zanz3c3jcq60dh94i12fn1d1-python3.11-pip-23.0.1/lib/python3.11/site-packages/pip (python 3.11)
~/langchainsupport3$ 

Inside of venv:

~/langchainsupport3$ source ./virt/bin/activate
(virt) ~/langchainsupport3$ pip -V
pip 23.2.1 from /home/runner/langchainsupport3/virt/lib/python3.11/site-packages/pip (python 3.11)
(virt) ~/langchainsupport3$ 

Modified Bash Script:

# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
    # reset old environment variables
    if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
        PATH="${_OLD_VIRTUAL_PATH:-}"
        export PATH
        unset _OLD_VIRTUAL_PATH
    fi
    if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
        PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
        export PYTHONHOME
        unset _OLD_VIRTUAL_PYTHONHOME
    fi
    #Added - For Replit / Nix OS Issues
    if [ -n "${_OLD_PIP_CONFIG_FILE:-}" ] ; then
        PIP_CONFIG_FILE="${_OLD_PIP_CONFIG_FILE:-}"
        export PIP_CONFIG_FILE
        unset _OLD_PIP_CONFIG_FILE
    fi
    #Added - For Replit / Nix OS Issues
    if [ -n "${_OLD_PYTHONPATH:-}" ] ; then
        PYTHONPATH="${_OLD_PYTHONPATH:-}"
        export PYTHONPATH
        unset _OLD_PYTHONPATH
    fi

    # This should detect bash and zsh, which have a hash command that must
    # be called to get it to forget past commands.  Without forgetting
    # past commands the $PATH changes we made may not be respected
    if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
        hash -r 2> /dev/null
    fi

    if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
        PS1="${_OLD_VIRTUAL_PS1:-}"
        export PS1
        unset _OLD_VIRTUAL_PS1
    fi

    unset VIRTUAL_ENV
    unset VIRTUAL_ENV_PROMPT
    if [ ! "${1:-}" = "nondestructive" ] ; then
    # Self destruct!
        unset -f deactivate
    fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="/home/runner/langchainsupport3/virt"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

#Added - For Replit / Nix OS Issues
_OLD_PYTHONPATH="$PYTHONPATH"
PYTHONPATH="$VIRTUAL_ENV/lib/python3.11/site-packages/"
export PYTHONPATH

#Added - For Replit / Nix OS Issues
_OLD_PIP_CONFIG_FILE="$PIP_CONFIG_FILE"
PIP_CONFIG_FILE="/home/runner/langchainsupport3/.config/pip.conf"
export PIP_CONFIG_FILE

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
    _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
    unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
    _OLD_VIRTUAL_PS1="${PS1:-}"
    PS1="(virt) ${PS1:-}"
    export PS1
    VIRTUAL_ENV_PROMPT="(virt) "
    export VIRTUAL_ENV_PROMPT
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands.  Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
    hash -r 2> /dev/null
fi

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.