我不知道如何在生产中使用外部库作为 python 模块。非常感谢您对此问题的任何帮助。
我在我的 django 应用程序中将FreeCAD作为 python 模块导入,如下所示。
视图.py
import sys
sys.path.append('freecad/lib')
import FreeCAD
import Part
Freecad bin 和 library 文件位于根目录,其中 manage.py 文件如下所示。
在我的本地服务器上一切正常。我可以导入 FreeCad 并对 CAD 文件进行数据处理。但是当我在谷歌云引擎上部署应用程序时,事情就开始崩溃了。部署后它抛出了这个错误。
Exception Value: libFreeCADApp.so: cannot open shared object file: No such file or directory
我还构建了这个应用程序的 docker 镜像以确保一致的依赖关系。但相同的结果本地服务器找到 Freecad 库并运行良好,但 docker 抛出此错误。
ModuleNotFoundError: No module named 'FreeCAD'
.
Docker 文件内容
# Base Image
FROM python:3.8.5
# set default environment variables # Dont wory about this
ENV PYTHONUNBUFFERED 1
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
# create and set working directory
RUN mkdir /app
WORKDIR /app
# Add current directory code to working directory
ADD . /app/
# Pass requirements to Docker
COPY ./requirements.txt /requirements.txt
# set project environment variables
# grab these via Python's os.environ
# these are 100% optional here
ENV PORT=8888
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
tzdata \
python3-setuptools \
python3-pip \
python3-dev \
python3-venv \
git \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# install environment dependencies
RUN pip3 install --upgrade pip
RUN pip3 install pipenv
RUN pip3 install -r /requirements.txt
# Install project dependencies
RUN pipenv install --skip-lock --system --dev
EXPOSE 8888
CMD gunicorn mod_project.wsgi:application --bind 0.0.0.0:$PORT
要求.txt
asgiref==3.3.1
cachetools==4.1.1
certifi==2020.12.5
cffi==1.14.4
chardet==3.0.4
cycler==0.10.0
Django==3.1.4
django-storages==1.10.1
google-api-core==1.23.0
google-auth==1.23.0
google-cloud-core==1.4.4
google-cloud-storage==1.33.0
google-crc32c==1.0.0
google-resumable-media==1.1.0
googleapis-common-protos==1.52.0
gunicorn==20.0.4
idna==2.10
kiwisolver==1.3.1
matplotlib==3.3.3
numpy==1.19.4
numpy-stl==2.13.0
Pillow==8.0.1
protobuf==3.14.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
PyMySQL==0.10.1
pyparsing==2.4.7
python-dateutil==2.8.1
python-utils==2.4.0
pytz==2020.4
requests==2.25.0
rsa==4.6
six==1.15.0
sqlparse==0.4.1
stripe==2.55.1
urllib3==1.26.2