hui怎么做网站,qq交流群怎么升级会员,如何做微信小程序网站,drupal 网站实例1#xff0c;背景#xff1a;
最近在学习langchain的课程#xff0c;里面创建自己的知识库的Retrieval模块中#xff0c;需要用到向量数据库。 所以按照官方的教程#xff08;vectorstores#xff09;#xff0c;准备使用chroma的向量数据库。图片来源 2#xff0c;问…1背景
最近在学习langchain的课程里面创建自己的知识库的Retrieval模块中需要用到向量数据库。 所以按照官方的教程vectorstores准备使用chroma的向量数据库。图片来源 2问题1pip安装出错
现象
第一步安装python包的时候出现了下面的错误 pip install chromadb Looking in indexes: https://mirror.baidu.com/pypi/simple/, https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting chromadbDownloading https://mirrors.aliyun.com/pypi/packages/7c/cc/8b822be150323492e1d3c2ae46ccd99ddc9841894afdc41c408ffd68918e/chromadb-0.4.22-py3-none-any.whl (509 kB)
......
Collecting importlib-metadata7.0,6.0 (from opentelemetry-api1.2.0-chromadb)Downloading https://mirrors.aliyun.com/pypi/packages/59/9b/ecce94952ab5ea74c31dcf9ccf78ccd484eebebef06019bf8cb579ab4519/importlib_metadata-6.11.0-py3-none-any.whl (23 kB) Installing collected packages: pypika, mpmath, monotonic, mmh3, flatbuffers, wrapt, websocket-client, uvloop, urllib3, tomli, sympy, python-dotenv, pyasn1, pulsar-client, overrides, opentelemetry-util-http, opentelemetry-semantic-conventions, opentelemetry-proto, oauthlib, importlib-metadata, humanfriendly, httptools, grpcio, googleapis-common-protos, chroma-hnswlib, bcrypt, backoff, asgiref, watchfiles, rsa, pyproject_hooks, pyasn1-modules, opentelemetry-exporter-otlp-proto-common, deprecated, coloredlogs, requests-oauthlib, posthog, opentelemetry-api, onnxruntime, google-auth, build, tokenizers, opentelemetry-sdk, opentelemetry-instrumentation, kubernetes, opentelemetry-instrumentation-asgi, opentelemetry-exporter-otlp-proto-grpc, opentelemetry-instrumentation-fastapi, chromadbAttempting uninstall: urllib3Found existing installation: urllib3 2.0.7Uninstalling urllib3-2.0.7:Successfully uninstalled urllib3-2.0.7Attempting uninstall: importlib-metadataFound existing installation: importlib-metadata 7.0.1Uninstalling importlib-metadata-7.0.1:
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: RECORD
Consider using the --user option or check the permissions. 原因分析
看上面的红色的部分安装的时候要求importlib-metadata的版本6.0版本7但是环境中默认的是7.0.1所以安装的时候想要把7的版本卸载安装6的版本问题出在卸载这里没有权限卸载。 为什么没有权限卸载我用的是百度平台的BML codeLab创建ipynb文件的时候选择的内核如下所以环境自带了python3的环境。这个包是python的一个标准库importlib-metadata)猜测可能是作为python环境的一部分 codeLab这边不允许修改。 解决方案
按照出错中的提示上图出错的黄色的部分 使用user模式进行python包的安装正常安装成功。 !pip install --user chromadb 补充 我有点好奇使用这个--user和没有使用有啥区别 后来发现两者的位置不同。
没有--user的时候安装到默认的python包的路径下面。 可以用pip show pkname找一个有的包查看python包的安装路径 codelab中默认的路径是/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages有--user的时候安装到用户的目录下面 通过pip show pkname的命令查看--user模式安装好的包的路径。 codelab中对应的--user模式下的路径是 /home/aistudio/.local/lib/python3.10/site-packages
3问题2导入模块失败ModuleNotFoundError : No module named chromadb
现象
上面安装之后正准备开开心心继续的时候发现虽然安装成功使用pip show能够正常看到包的信息但是使用Langchain生成数据库的实例的时候会报错 原因是在langchain中引入chromadb的模块时候提示模块不存在。(import chromadb失败 # 定义一个向量数据库的实例 vectorDB Chroma( collection_namelangchain_store, embedding_functionqianfan_embedding_model) 原因分析
python导包的时候会查找内置模块以及sys.path中的路径。 确认一下sys.path的设定里面是没有上面安装的本地用户的路径的 所以虽然包正常安装但是import的时候找不到所以报错。 import sys print(sys.path) [/home/aistudio, /opt/conda/envs/python35-paddle120-env/lib/python310.zip, /opt/conda/envs/python35-paddle120-env/lib/python3.10, /opt/conda/envs/python35-paddle120-env/lib/python3.10/lib-dynload, , /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages] 解决方案
把--user模式下的安装路径加入到sys.path中。 不同的环境下安装的路径可能有所不同使用命令[pip show 包名] 查看安装的路径。 sys.path.append(/home/aistudio/.local/lib/python3.10/site-packages) 之后就可以正常import了。 4后记
这个问题搞了一上午整体来看对于pip安装的细节比如安装路径以及安装之后import导入的细节包是怎么查找的不是特别清楚导致调查花了一些时间。 mark一下也希望分享给有类似问题的小伙伴。