# Langchain-huggingface

**URL:** <https://discuss.huggingface.co/t/langchain-huggingface/92212>\
**Category:** Beginners\
**Created:** [June 14, 2024, 3:09pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212 "2024-06-14T15:09:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marky2376](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@marky2376](https://discuss.huggingface.co/u/marky2376)\
**Post date:** [June 14, 2024, 3:09pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/1 "2024-06-14T15:09:32Z")

</div>

Hello, the langchain x huggingface framework seems perfect for what my team is trying to accomplish.

I installed langchain-huggingface with pip3 in a venv and following this guide, [Hugging Face x LangChain : A new partner package](https://huggingface.co/blog/langchain) I created a module like this but with a llma3 model:

```auto
from langchain_huggingface import HuggingFacePipeline

llm = HuggingFacePipeline.from_model_id(
    model_id="microsoft/Phi-3-mini-4k-instruct",
    task="text-generation",
    pipeline_kwargs={
        "max_new_tokens": 100,
        "top_k": 50,
        "temperature": 0.1,
    },
)
llm.invoke("Hugging Face is")

```

I get the following error when I try to run the script:

ModuleNotFoundError: No module named ‘langchain\_huggingface’

I must be missing something or doing something very basic wrong.

---

<div class="post-metadata">

**Author:** ![Jofthomas](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jofthomas/32/28378_2.png) [@Jofthomas](https://discuss.huggingface.co/u/Jofthomas)\
**Post date:** [June 18, 2024, 7:19pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/2 "2024-06-18T19:19:05Z")

</div>

Hey @marky2376,

I’m the author of the blog post, I’ll try to help you.

I just retested the install and the import and both worked.

“ModuleNotFoundError” are usually errors when you are not executing the code in the same environment as where you installed the library.

Can you see langchain\_huggingface in your `!pip3 list` ?

A second option is that you had a conflict in the installation of the library that you did not see ( the requirements of the libs include the latest version of tokenizers which might enter in conflict with other libs )

---

<div class="post-metadata">

**Author:** ![marky2376](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@marky2376](https://discuss.huggingface.co/u/marky2376)\
**Post date:** [June 18, 2024, 7:42pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/3 "2024-06-18T19:42:43Z")

</div>

I tried installing both inside and outside the venv, here is the list for both:

mneely@llmmaximus:/usr/projects/langface$ !pip3 list  
pip3 install langchain-huggingface list  
Defaulting to user installation because normal site-packages is not writeable  
Requirement already satisfied: langchain-huggingface in /usr/local/lib/python3.10/dist-packages (0.0.3)  
ERROR: Could not find a version that satisfies the requirement list (from versions: none)  
ERROR: No matching distribution found for list

(.venv) mneely@llmmaximus:/usr/projects/langface$ !pip3 list  
pip3 install langchain-huggingface list list list  
Collecting langchain-huggingface  
Using cached langchain\_huggingface-0.0.3-py3-none-any.whl (17 kB)  
ERROR: Could not find a version that satisfies the requirement list (from versions: none)  
ERROR: No matching distribution found for list  
(.venv) mneely@llmmaximus:/usr/projects/langface$

---

<div class="post-metadata">

**Author:** ![Jofthomas](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jofthomas/32/28378_2.png) [@Jofthomas](https://discuss.huggingface.co/u/Jofthomas)\
**Post date:** [June 18, 2024, 8:02pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/4 "2024-06-18T20:02:52Z")

</div>

Alright, you have typos in your shared logs :

> [@marky2376](#):
>
> ERROR: No matching distribution found for list

You have `pip3 install langchain-huggingface list list list`

Outside of the error from typo, I can see that:  
outside the env, the latest version ( 0.0.3 ) is installed 😉

> [@marky2376](#):
>
> Requirement already satisfied: langchain-huggingface in /usr/local/lib/python3.10/dist-packages (0.0.3)

And inside it’s being reinstalled from cache because you most likely uninstalled before :

> [@marky2376](#):
>
> Using cached langchain\_huggingface-0.0.3-py3-none-any.whl (17 kB)

So, can you now give me the output of pip list ?

Or alternatively do the following :

1. enter python
2. test the import

```auto
joffreythomas@MBP-de-joffrey % python                        
Python 3.11.6 (main, Oct 2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from langchain_huggingface import HuggingFacePipeline
>>> 

```

---

<div class="post-metadata">

**Author:** ![marky2376](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@marky2376](https://discuss.huggingface.co/u/marky2376)\
**Post date:** [June 18, 2024, 8:31pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/5 "2024-06-18T20:31:28Z")

</div>

I’m just typing “!pip3 list” and that command is out putting “list” multiple times. Maybe because I have attempted ~3 installs in my troubleshooting? I have never used that list command before so not sure.

(.venv) mneely@llmmaximus:/usr/projects/langface$ python3  
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux  
Type “help”, “copyright”, “credits” or “license” for more information.

> > > from langchain\_huggingface import HuggingFacePipeline  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > ModuleNotFoundError: No module named ‘langchain\_huggingface’

No, if I try outside the venv, I get what you have:

> > > from langchain\_huggingface import HuggingFacePipeline

So I actually tried running my script again outside the venv, which I thought I had before. It executes and finds the package. (I get another error).

What am I missing from being able to run this in a venv?

---

<div class="post-metadata">

**Author:** ![Jofthomas](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jofthomas/32/28378_2.png) [@Jofthomas](https://discuss.huggingface.co/u/Jofthomas)\
**Post date:** [June 19, 2024, 4:23pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/6 "2024-06-19T16:23:27Z")

</div>

Pip list is a command that will list all your installed packages.

Alright, so outside the env it is installed.

Once in, you can :

1. Unintall `pip uninstall langchain-huggingface`
2. Re-install `pip install langchain-huggingface`
3. verify installation

```auto
joffreythomas@MBP-de-joffrey test % pip show langchain-huggingface
Name: langchain-huggingface
Version: 0.0.3
Summary: An integration package connecting Hugging Face and LangChain
Home-page: https://github.com/langchain-ai/langchain
Author: 
Author-email: 
License: MIT
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: huggingface-hub, langchain-core, sentence-transformers, tokenizers, transformers
Required-by: 

```

If you have a problem during the installation process, please copy the log.

---

<div class="post-metadata">

**Author:** ![gaston770](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gaston770](https://discuss.huggingface.co/u/gaston770)\
**Post date:** [September 6, 2024, 7:04pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/7 "2024-09-06T19:04:30Z")

</div>

Was having the same issue and scratched my head for a while, solution was pretty simple. The solution is to install jupyter from within the activated venv. So,

1. activate environment  
at any time) install all your required library like langchain\_huggingface
2. install jupyter notebook
3. run jupyter notebook

---

<div class="post-metadata">

**Author:** ![marky2376](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@marky2376](https://discuss.huggingface.co/u/marky2376)\
**Post date:** [September 6, 2024, 7:21pm UTC](https://discuss.huggingface.co/t/langchain-huggingface/92212/8 "2024-09-06T19:21:16Z")

</div>

> [@gaston770](#):
>
> jupyter

Very nice. I ended up not using a venv at all for now. I have gotten pretty far on my journey, and need to go back and reinstall all my packages within a venv. Getting my application to run as a service is near impossible without it being in venv, so that’s my next major step. Not using juputer, so I will have to figure it out as I go.
