简体   繁体   English

How to add local python files as a library to python virtual environment the same way as pip install to Airflow Docker

[英]How to add local python files as a library to python virtual environment the same way as pip install to Airflow Docker

  • How to install my own python package to python virtual environment?如何安装我自己的 python package 到 python 虚拟环境?
  • Final goal would be to add that package to a Airflow Docker environment.最终目标是将 package 添加到 Airflow Docker 环境中。
  • My Dockerfile:我的 Dockerfile:
FROM apache/airflow:latest-python3.8
COPY requirements.txt .
RUN pip install -r requirements.txt

First, check the answer here https://stackoverflow.com/a/56483981/11609051 for the installation of your package to the venv.首先,在这里查看https://stackoverflow.com/a/56483981/11609051的答案,以便将 package 安装到 venv。

After that you need to extend your docker image.之后,您需要扩展您的 docker 映像。 For this your Dockerfile.txt should be similar to:为此,您的 Dockerfile.txt 应类似于:

FROM apache/airflow:2.4.0
WORKDIR /Users/Desktop/tools/airflow2.4-lite
COPY requirements.txt /requirements.txt
RUN pip install --user --upgrade pip
RUN pip install --no-cache-dir --user -r /requirements.txt 

then you need to run command:那么你需要运行命令:

docker build . -f Dockerfile.txt 

However there are some points that needs to be taken into account.但是,有一些点需要考虑。

  • Your requirements.txt file should be in your Airflow Docker project file.您的 requirements.txt 文件应该在您的 Airflow Docker 项目文件中。
  • Any of your packages in your venv shouldn't have the dependency of Python greater than of your Airflow's which is Python 3.8 nor they shouldn't depend on a package that uses a dependent rely on greater than Python 3.8. Any of your packages in your venv shouldn't have the dependency of Python greater than of your Airflow's which is Python 3.8 nor they shouldn't depend on a package that uses a dependent rely on greater than Python 3.8.
  • For the above you can use the Homebrew's Python@3.8 and you can install the packages in site-packages directory with: pip3.8 install <package-name> command.对于上述情况,您可以使用 Homebrew 的 Python@3.8,您可以使用以下命令将软件包安装在 site-packages 目录中: pip3.8 install <package-name>命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Pip (OS X) 在虚拟环境中安装 Python 包 - How to install a Python package inside a virtual environment with Pip (OS X) 如何在 python 中激活虚拟环境时使用 pip 安装 - How to use pip install while activating virtual environment in python Python:如何在临时目录创建虚拟环境并使用 pip 安装模块 - Python: How to create a virtual environment at temp dir and install modules with pip 如何在 python 的虚拟环境中安装 pip 后访问资源文件? - how to access resource files after pip install in virtual env in python? 是否有必要在 python 的虚拟环境中安装请求库? - is it necessary to install Requests library at Virtual Environment in python? 在 python 的虚拟环境中安装 pip 后无法导入 tensorflow - unable to import tensorflow after I pip install in a virtual environment in python 在虚拟环境中使用PIP,如何安装MySQL-python - Using PIP in a virtual environment, how do I install MySQL-python 有没有办法在相同的conda环境中安装python 3和python 2? - Is there a way to install python 3 and python 2 in the same conda environment? 如何pip安装本地python包? - How to pip install a local python package? 如何在centos的虚拟环境中安装活动python - How to install active python in virtual environment on centos
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM