Note, I'm brand new to docker.
I'm trying to create a docker image of my flask app but when I run sudo docker image build -t flask_docker . it keeps throwing version errors at the step of installing the requirements.txt file.
Here is my docker file
FROM python:3.8-alpine
COPY requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip3 install -r requirements.txt
COPY . /app
ENTRYPOINT ["python3"]
CMD ["app.py"]
And here is the error.
ERROR: Could not find a version that satisfies the requirement Brlapi==0.8.2 (from versions: none)
ERROR: No matching distribution found for Brlapi==0.8.2
WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
What is the proper way to fix this error? Should I just manually go through and find which packages don't install properly and just remove them?
I would recommend using a Virtual environment to install packages, but for your situation try reinstalling Brlapi with
pip install --upgrade --force-reinstall Brlapi
and then pip freeze to get your requirements.txt
Related
when I run 'docker build .' command,
"ERROR: Invalid requirement: 'Django=>4.0.4' (from line 1 of /requirements.txt)
WARNING: You are using pip version 22.0.4; however, version 22.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command."
this error shows up. I have upgraded pip to the latest version. When I check version of pip , it shows 22.1.
But when I run docker build command again, nothing changes.
I have upgraded from this /usr/local/bin/python location. but still nothing changed.
I am using Ubuntu 20.04, python version is 3.8.
my docker file:
FROM python:3.8-alpine
MAINTAINER Kanan App Developer
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /app
WORKDIR /app
COPY ./app /app
RUN adduser -D user
USER user
requirements.txt file:
Django=>4.0.4
djangorestframework=>3.13.1
Just use == or >= instead => in your requirements.txt, like this
Django==4.0.4
djangorestframework==3.13.1
=> is not a valid realtional operator for greater than or equal to.
The valid operator is >=. So, your requirements.txt file should be:
Django>=4.0.4
djangorestframework>=3.13.1
I am using docker tutorial (https://docs.docker.com/language/python/build-images/) to build a simple python app. Using freeze command I made requirements.txt file which consists a lot of packages.
When I want to build the docker image, I am getting this error:
Step 4/6 : RUN pip3 install -r requirements.txt ---> Running in
f92acd21d271
ERROR: Could not find a version that satisfies the requirement
apt-clone==0.2.1 (from versions: none)
ERROR: No matching distribution found for apt-clone==0.2.1
The command '/bin/sh -c pip3 install -r requirements.txt' returned a
non-zero code: 1
This is my dockerfile contents (same as what is mentioned in the tutorial):
# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
CMD [ "python3", "-m", "flask","run","--host=0.0.0.0" ]
It's not related to apt-clone==0.2.1 package. Whatever I try to install in the docker image, it fails. I tried apt update and installing pip3 in the dockerfile too but didn't work.
What did I miss?
pip3 freeze outputs the package and its version installed in the current environment, no matter the package installed by pip or with other methods.
In fact, apt-clone==0.2.1 comes from debian package repo, not from pypi.org, see next:
$ pip3 freeze | grep apt-clone
$ apt-get install -y apt-clone
$ dpkg -l apt-clone
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii apt-clone 0.4.1 all Script to create state bundles
$ dpkg -L apt-clone
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/apt-clone
/usr/share/doc/apt-clone/copyright
/usr/share/doc/apt-clone/changelog.gz
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/apt-clone.8.gz
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/apt_clone.py
/usr/lib/python3/dist-packages/apt_clone-0.2.1.egg-info
/usr/bin
/usr/bin/apt-clone
$ pip3 freeze | grep apt-clone
apt-clone==0.2.1
You could see from above, the apt_clone.py & apt_clone-0.2.1.egg-info are installed by debian package apt-clone, the 0.4.1 is just the debian package version, while 0.2.1 is the python package version.
So, for apt-clone similar, you need to install them with apt although they are seen in pip3 freeze.
There is no package named apt-clone in the public PyPI repository, so pip3 obviously cannot find it.
If you actually have a Python package named like this, where did it come from?
If you created a package with this name locally, you need to install it too in your Docker image somehow.
If you are inside an organization, maybe you have a local PyPI with different packages than the public one, and then you need to configure pip3 to use it (try pip3 -i http://your.local.pypi/simple -r requirements.txt where obviously the URL needs to be something else, but we can't guess what).
If pip3 freeze says you have this package, it must have come from somewhere, but we don't know where. You have to figure that out, or supply more details to help us help you.
There is a Debian package named apt-clone but that obviously isn't something pip can install. Did you actually mean apt-get install -y apt-clone==0.2.1? (I can only find version 0.4.1 in Debian Buster, though.)
... #atline's answer explains what happened (you should probably accept that) but the simple fix is to manually populate requirements.txt with your actual requirements. pip3 freeze is a nice shorthand for that if you are in a virtual environment, but it's not a proper replacement for a manually curated requirements.txt or setup.py (or its modern replacements, currently moving from setup.cfg to pyproject.toml). If flask is the only package your app needs, simply put pip3 install flask and don't create a requirements.txt.
I have a requirement.txt file with the list of python package to install. One of the packages is psycopg2==2.6.2 I need to update this package to psycopg2==2.7. I tried to install by pip3 install psycopg2 But it doesn't affect requirement.txt file. Can you please point me in the right direction?
Notice that running pip3 install psycopg2 doesn't respect the requirements.txt file. To upgrade this package you need to use -U option:
pip3 install -U psycopg2
which is a shorthand for:
pip3 install --upgrade psycopg2
After that, you can update your requirements.txt with the following command:
pip freeze > requirements.txt
If you're looking for a solution to automatically update the requirements.txt file after you upgrade package/packages, you can use pip-upgrader.
Installation:
pip install pip-upgrader
Usage:
pip-upgrade
The above command auto-discovers the requirements file and prompts for selecting upgrades. You can also specify a path to the requirements file or/and specify a package to upgrade:
pip-upgrade /path/to/requirements.txt -p psycopg2
As you've discovered, pip doesn't update the requirements file. So the workflow you'd likely want to use is:
Update the version of psycopg2 in your requirements file from 2.6.2 to 2.7
Run pip install with the upgrade flag
pip3 install -U -r requirements.txt
If you're familiar with tools like npm that do update the version in the catalog file, you may be interested in using pipenv, which manages your dependencies and the virtual environment for you, much like npm does.
If you don't know the latest version of your package, then use pip to figure it out:
$ pip list --outdated | grep psycopg2
psycopg2 (2.7.3.2) - Latest: 2.7.4 [wheel]
you can try:
pip install --upgrade --force-reinstall -r requirements.txt
You can also ignore installed package and install the new one :
pip install --ignore-installed -r requirements.txt
I looked up how to install multiple packages from a requirements document using pip. The answers were mostly:
pip install -r requirements.txt
What does the -r do though? I can't find an answer for this and it isn't listed when I run pip help.
Instead of pip --help, look into pip install --help:
-r, --requirement Install from the given requirements
file. This option can be used multiple
times.
Also see these documentation paragraphs:
pip install
Requirements Files.
-r will search for requirement file.
pip install --help
will help you !!
May, 2022 Update:
If you run this command below without "-r":
pip install requirements.txt
You will get this error below:
ERROR: Could not find a version that satisfies the requirement requirements.txt (from versions: none)
HINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txt
ERROR: No matching distribution found for requirements.txt
Because "pip" tries to install the package "requirements.txt" instead of installing the packages listed in "requirements.txt". Of cource, the package "requirements.txt" doesn't exist in PyPI while for example, the packages "django" and "pillow" exist in PyPI:
pip install django
pip install pillow
So, to install the packages listed in "requirements.txt", you must need "-r";
pip install -r requirements.txt
You can check what "-r" means by running the command below:
pip install --help
-r, --requirement Install from the given requirements file. This option can be used multiple times.
In your case pip install -r requirements.txt will install the libraries listed in your requirements.txt file.
pip install requirements.txt
Above statement looks for a python package named requirements.txt. No such package exists. Your intention is that pip install opens the txt and reads the packages from there. The -r allows pip install to open requirements.txt and install the packages inside of it instead.
I have a requirements.txt file containing all my dependencies but it is not processed correctly :
After a pip install -r requirements.txt, I get the following pip freeze :
argparse==1.2.1
wsgiref==0.1.2
But when I do a pip install of :
numpy==1.6.2
Django==1.4.2
django-tastypie==0.9.14
pyes==0.19.1
And then run my pip install -r requirements.txt . Then it works.
Here is what my requirements.txt contains :
numpy==1.6.2
Django==1.4.2
django-tastypie==0.9.14
urllib3==1.5
pyes==0.19.1
BeautifulSoup==3.2.1
MySQL-python==1.2.3
IMAPClient==0.9.1
Jinja2==2.6
Pillow==2.0.0
amqp==1.0.9
anyjson==0.3.3
billiard==2.7.3.22
celery==3.0.16
django-celery==3.0.11
django-compressor==1.3
django-concurrency
django-extensions==1.1.1
https://codeload.github.com/toastdriven/django-haystack/zip/master#egg=django-haystack
django-model-utils==1.2.0
django-multiforloop==0.2.1
django-social-auth==0.7.22
html5lib==0.95
httplib2==0.8
kombu==2.5.7
logilab-astng==0.24.2
logilab-common==0.59.0
oauth2==1.5.211
ordereddict==1.1
pycrypto==2.6
pylint==0.27.0
python-dateutil==1.5
python-openid==2.2.5
pytz==2013b
six==1.3.0
unittest2==0.5.1
wsgiref==0.1.2
xlrd==0.9.0
xmltodict==0.4.6
django-storages>=1.1.8
boto==2.8.0
lxml==3.1.0
pyelasticsearch==0.4.1
django-tastypie-elasticsearch==0.1.0
Would anyone have a solution ?
I tried this out and the problem is with django-tastypie-elasticsearch. There is a known issue, whereby installation with pip fails if Django hasn't been installed yet. Here is the issue report:
https://github.com/llonchj/django-tastypie-elasticsearch/issues/1
Looks like django-tastypie-elastic has only two contributors, so you're probably on your own. The good news is that it wasn't your fault!
On mac:
To get your already installed dependencies
pip3 freeze > requirements.txt
from: Automatically create requirements.txt
Then if you want to install them, and you are using a virtual environment
pip3 install -r requirements.txt
from:
How can I install packages using pip according to the requirements.txt file from a local directory?
If you want to update them
I just know how to do it with pip-review.
https://pypi.org/project/pip-review/#description
pip3 install pip-review or pip install pip-review
then pip-review --local --auto
from:
How to upgrade all Python packages with pip
The "https://codeload.github.com/toastdriven/django-haystack/zip/master#egg=django-haystack" line is not a valid pip requirement. It should read "-e git+https://codeload.github.com/toastdriven/django-haystack/zip/master#egg=django-haystack"