pip install: metadata-generation-failed in docker - docker

This is my Dockerfile:
FROM alpine:3.14
# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add python3-dev # for python3.x installs
RUN apk add musl-dev
RUN apk add gcc
RUN mkdir -p /usr/src/tap-stashstock
RUN mkdir -p /usr/singer
WORKDIR /usr/src/tap-stashstock
ADD . /usr/src/tap-stashstock
ADD singer /usr/singer
RUN pip3 install --upgrade .
This works and then I run docker run -it stashstock-to-bigquery pip3 install target-bigquery which results in this error
Collecting grpcio<2.0dev,>=1.38.1
Downloading grpcio-1.44.0.tar.gz (21.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.4/21.4 MB 3.9 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-4wuwnk4b/grpcio_429c1ed72b4244a0a71ac7e9f1ec81c6/setup.py", line 256, in <module>
if check_linker_need_libatomic():
File "/tmp/pip-install-4wuwnk4b/grpcio_429c1ed72b4244a0a71ac7e9f1ec81c6/setup.py", line 203, in check_linker_need_libatomic
cpp_test = subprocess.Popen([cxx, '-x', 'c++', '-std=c++11', '-'],
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'c++'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
What am I missing from my Dockerfile?

This error may for not having a C/C++ compiler.
Try install gcc and build-essensial before pip installation.
Please follow the steps given in
https://github.com/grpc/issues/24556

Related

How to add TailwindCSS to Docker container?

I'm trying to add TailwindCSS to Docker container but after running tailwindcss command in bash, it just says:
Traceback (most recent call last):
File "/usr/local/bin/tailwindcss", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/__main__.py", line 9, in main
completed_process = pytailwindcss.run(
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/__init__.py", line 45, in run
install(version, bin_path)
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/__init__.py", line 69, in install
return install_binary(version, ensure_is_pathlib_path(bin_path))
File "/usr/local/lib/python3.10/site-packages/pytailwindcss/installation.py", line 25, in install_binary
os.makedirs(bin_path.parent, exist_ok=True)
File "/usr/local/lib/python3.10/os.py", line 225, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.10/site-packages/pytailwindcss/bin
Dockerfile:
FROM mcr.microsoft.com/vscode/devcontainers/python:3.10-bullseye
ENV PYTHONUNBUFFERED=1
WORKDIR /app
ARG FLASK_APP=project.app
ENV FLASK_APP=${FLASK_APP}
ARG FLASK_RUN_PORT=5001
ENV FLASK_RUN_PORT=${FLASK_RUN_PORT}
CMD flask run --host=0.0.0.0 # --port=${FLASK_RUN_PORT} --app=${FLASK_APP}
COPY requirements.txt /tmp/pip-tmp/
RUN pip --disable-pip-version-check install -r /tmp/pip-tmp/requirements.txt && \
rm -rf /tmp/pip-tmp
COPY . .
RUN pip --disable-pip-version-check install -v -e .
ARG CI_COMMIT_SHA
ENV CI_COMMIT_SHA=${CI_COMMIT_SHA}
RUN echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> /app/.env
ARG USERNAME=vscode
RUN test ! -z "${USERNAME}" && mkdir -p /home/${USERNAME}/.vscode-server/extensions && \
chown -R $USERNAME /home/$USERNAME/.vscode-server
EDIT:
Requirements.txt
importlib-metadata
flask
python-dotenv
flask-login
passlib
flask-mongoengine
python-dateutil
pytailwindcss
pre-commit
sentry-sdk[flask]
sentry-sdk[pymongo]
Any idea how to make TailwindCSS work in a Docker container?

Cannot run python script in Docker using chromedriver

After building the Docker file, trying to run the image when the python sript starts return this error:
Traceback (most recent call last):
File "/data/ms_rewards_farmer.py", line 815, in <module>
browser = browserSetup(True, PC_USER_AGENT)
File "/data/ms_rewards_farmer.py", line 48, in browserSetup
chrome_browser_obj = webdriver.Chrome(options=options)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line
69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line
89, in __init__
self.service.start()
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 71,
in start self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: 'chromedriver'
This is the Dockerfile:
FROM python:3.9.2
RUN mkdir -p /logs
RUN apt-get update
RUN apt install wget
RUN apt-get install -y wget xvfb unzip
# install google chrome
RUN apt-get install -y chromium
# install chromedriver
RUN wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip
RUN mv chromedriver /usr/bin/chromedriver
RUN chown root:root /usr/bin/chromedriver
RUN chmod +x /usr/bin/chromedriver
COPY . /data
WORKDIR /data
RUN pip install --no-cache-dir -r requirements.txt
# set display port to avoid crash
ENV DISPLAY=:99
# Custom Env Vars
ENV DOCKER_IMAGE=true
I don't know what's the problem, i tried to change the installation of chromedriver from the Dockerfile, any ideas?
Requirements.txt:
certifi
chardet
idna
requests
selenium
urllib3
ipapi
schedule

PermissionError: [Errno 13] Permission denied: '/app/manage.py'

I run docker-compose command and get "PermissionDenied" error. I have used the same code about 2 month ago and it worked perfectly. I have searched internet and solutions didn't help much.
docker-compose run --rm app sh -c "django-admin startproject app ."
And it gives me an error:
Traceback (most recent call last):
File "/py/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/py/lib/python3.9/site-packages/django/core/management/commands/startproject.py", line 21, in handle
super().handle('project', project_name, target, **options)
File "/py/lib/python3.9/site-packages/django/core/management/templates.py", line 160, in handle
with open(new_path, 'w', encoding='utf-8') as new_file:
PermissionError: [Errno 13] Permission denied: '/app/manage.py'
My Dockerfile is :
FROM python:3.9-alpine3.13
LABEL maintainer="Kananappdeveloper"
ENV PYHTONUNBUFFERED 1
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000
ARG DEV=false
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
adduser \
--disabled-password \
--no-create-home \
django-user
ENV PATH="/py/bin:$PATH"
USER django-user
My OS is Ubuntu 22.04
Thank you in advance.

Unable to run geckodriver on Docker image with Mac M1 chip. selenium WebDriverException: Message: Process unexpectedly closed with status 1

I've successfully built a Docker image but can't seem to be able to run it. This is my Dockerfile:
FROM python:3.9
RUN apt-get update
#install system depend
RUN apt-get install -y software-properties-common
#Download and install Fire
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A6DCF7707EBC211F
RUN apt-add-repository "deb http://ppa.launchpad.net/ubuntu-mozilla-security/ppa/ubuntu bionic main" -y
RUN apt-get update -y
RUN apt-get install firefox -y
# Download and install geckodriver
RUN GECKODRIVER_VERSION=$(curl https://github.com/mozilla/geckodriver/releases | grep -Eo 'v0+.[0-9]+.[0-9]+' | head -1) && \
wget https://github.com/mozilla/geckodriver/releases/download/"$GECKODRIVER_VERSION"/geckodriver-"$GECKODRIVER_VERSION"-macos-aarch64.tar.gz && \
tar -xvzf geckodriver* && \
chmod +x geckodriver && \
mv geckodriver /usr/local/bin
ENV DISPLAY=:99
#Install depend and cop files
COPY . .
RUN pip install -r requirements.txt
CMD ["python3", "scrapper_class.py"]
I've also got a scrapper_class.py file, in which I do:
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
...
self.driver = webdriver.Firefox(service = Service(GeckoDriverManager().install()))
and it's throwing this error:
Traceback (most recent call last):
File "//scrapper_class.py", line 914, in <module>
bot = Scrapper()
File "//scrapper_class.py", line 31, in __init__
self.driver = webdriver.Firefox(service = Service(GeckoDriverManager().install()))
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 181, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 269, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 425, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
can anyone tell me what I'm doing wrong?

ModuleNotFoundError: No module named 'OpenSSL' while creating Dockerfile

I create the docker file for my flask app that is running on port 3000.
That is my docker file
<-----------------Dockerfile---------------------->
FROM python:3
WORKDIR /app
EXPOSE 3000
COPY ./requirements.txt ./
RUN pip install -r requirements.txt
COPY ./ ./
CMD ["python","run.py"]
<--------------------- requirements.txt--------------------------------->
I generated it by using "pipreqs"
pyOpenSSL==20.0.1
Flask_Login==0.5.0
SQLAlchemy==1.3.12
Flask_WTF==0.15.1
WTForms==2.3.3
Flask_SQLAlchemy==2.5.1
Flask_Bcrypt==0.7.1
Flask==2.0.1
Pillow==8.3.2
secrets==1.0.2
<------------------------------Error that I encounter------------------------------>
E
RROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-aesbht7l/secrets_faf11378a9b945deb5114ab973cefa73/setup.py'"'"'; __file__='"'"'/tmp/pip-install-aesbht7l/secrets_faf11378a9b945deb5114ab973cefa73/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ub_x6ltz
cwd: /tmp/pip-install-aesbht7l/secrets_faf11378a9b945deb5114ab973cefa73/
Complete output (12 lines):
Traceback (most recent call last):
File "/tmp/pip-install-aesbht7l/secrets_faf11378a9b945deb5114ab973cefa73/setup.py", line 10, in <module>
import OpenSSL
ModuleNotFoundError: No module named 'OpenSSL'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-aesbht7l/secrets_faf11378a9b945deb5114ab973cefa73/setup.py", line 12, in <module>
raise ImportError('Installing this module requires OpenSSL python bindings')
ImportError: Installing this module requires OpenSSL python bindings
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/93/c4/166925e31bc06bfe49deb4dc3922584790a33b897509bac388acdc074a60/secrets-1.0.2.tar.gz#sha256=37075ab08607092e76da2b86e94dd38a0216ec80088a0a3f9220077750aeddf9 (from https://pypi.org/simple/secrets/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement secrets==1.0.2 (from versions: 1.0.2)
ERROR: No matching distribution found for secrets==1.0.2
I even added pyOpenSSL in requirements.txt but the error keeps saying like that. Did I choose the wrong python image? Is it related to that?
Consider installing additional packages:
FROM python:3
WORKDIR /app
EXPOSE 3000
RUN apt-get update
RUN apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
COPY ./requirements.txt ./
RUN pip install -r requirements.txt
COPY ./ ./
CMD ["python","run.py"]
(got the answer from here: I can't install python-ldap)

Resources