euler314 commited on
Commit
368bfff
·
verified ·
1 Parent(s): 6e36ad3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -5
Dockerfile CHANGED
@@ -1,5 +1,8 @@
1
  FROM python:3.10-slim
2
 
 
 
 
3
  WORKDIR /home/user/app
4
 
5
  # Install system dependencies
@@ -19,15 +22,36 @@ RUN pip install --no-cache-dir -r requirements.txt
19
  # Copy C++ source and app
20
  COPY cubic_cpp.cpp app.py ./
21
 
22
- # Compile the C++ module and handle errors
23
- RUN g++ -O3 -shared -std=c++11 -fPIC \
 
 
 
24
  $(python3-config --includes) \
25
  -I$(python3 -c "import pybind11; print(pybind11.get_include())") \
26
  -I$(python3 -c "import numpy; print(numpy.get_include())") \
27
  cubic_cpp.cpp \
28
- -o cubic_cpp$(python3-config --extension-suffix) && \
29
- ln -sf $(pwd)/cubic_cpp$(python3-config --extension-suffix) /usr/local/lib/python3.10/site-packages/ && \
30
- python3 -c "import cubic_cpp; print('C++ module successfully compiled and imported')"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # Run the application
33
  CMD ["streamlit", "run", "app.py"]
 
1
  FROM python:3.10-slim
2
 
3
+ # Set environment variable to ensure extension suffix is correct
4
+ ENV PYTHONPATH=/home/user/app:$PYTHONPATH
5
+
6
  WORKDIR /home/user/app
7
 
8
  # Install system dependencies
 
22
  # Copy C++ source and app
23
  COPY cubic_cpp.cpp app.py ./
24
 
25
+ # Use a more robust compilation approach
26
+ RUN python3 -c "import numpy; import pybind11; import sys; print(f'Python executable: {sys.executable}, Python version: {sys.version}')" && \
27
+ EXT_SUFFIX=$(python3-config --extension-suffix) && \
28
+ echo "Extension suffix: ${EXT_SUFFIX}" && \
29
+ g++ -O3 -shared -std=c++11 -fPIC \
30
  $(python3-config --includes) \
31
  -I$(python3 -c "import pybind11; print(pybind11.get_include())") \
32
  -I$(python3 -c "import numpy; print(numpy.get_include())") \
33
  cubic_cpp.cpp \
34
+ -o cubic_cpp${EXT_SUFFIX} && \
35
+ # Copy to multiple possible locations
36
+ cp cubic_cpp${EXT_SUFFIX} /usr/local/lib/python3.10/site-packages/ && \
37
+ # List all created files
38
+ ls -la /home/user/app && \
39
+ ls -la /usr/local/lib/python3.10/site-packages/ | grep cubic && \
40
+ # Verify the module can be imported
41
+ python3 -c "import sys; print(sys.path); import cubic_cpp; print('Successfully imported cubic_cpp:', cubic_cpp.__file__)"
42
+
43
+ # Update app.py to add additional path checks
44
+ RUN sed -i '1s/^/import os, sys\n\
45
+ # Add current directory to path\n\
46
+ module_paths = [os.getcwd(), "\/home\/user\/app", "\/home\/user\/a"]\n\
47
+ for path in module_paths:\n\
48
+ if path not in sys.path:\n\
49
+ sys.path.insert(0, path)\n\
50
+ if os.path.exists(path):\n\
51
+ print(f"Path exists: {path}")\n\
52
+ files = [f for f in os.listdir(path) if "cubic_cpp" in f]\n\
53
+ if files:\n\
54
+ print(f"Found module files in {path}: {files}")\n\n/' app.py
55
 
56
  # Run the application
57
  CMD ["streamlit", "run", "app.py"]