Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pathlib: cannot import name 'Sequence' from 'collections'

It has been a few days since I rebuilt my project but when I was testing some things this morning I wanted to update my Werkzeug package due to an issue I was having with its Multidict class, I rebuilt and started getting this error:

#17 73.14     ERROR: Command errored out with exit status 1:
#17 73.14      command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0qw1gt47/pathlib_cc19f11e095d4bbd895469d77780e6c9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0qw1gt47/pathlib_cc19f11e095d4bbd895469d77780e6c9/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-908_ate4
#17 73.14          cwd: /tmp/pip-install-0qw1gt47/pathlib_cc19f11e095d4bbd895469d77780e6c9/
#17 73.14     Complete output (13 lines):
#17 73.14     Traceback (most recent call last):
#17 73.14       File "<string>", line 1, in <module>
#17 73.14       File "/usr/local/lib/python3.10/site-packages/setuptools/__init__.py", line 16, in <module>
#17 73.14         import setuptools.version
#17 73.14       File "/usr/local/lib/python3.10/site-packages/setuptools/version.py", line 1, in <module>
#17 73.14         import pkg_resources
#17 73.14       File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 23, in <module>
#17 73.14         import zipfile
#17 73.14       File "/usr/local/lib/python3.10/zipfile.py", line 19, in <module>
#17 73.14         import pathlib
#17 73.14       File "/tmp/pip-install-0qw1gt47/pathlib_cc19f11e095d4bbd895469d77780e6c9/pathlib.py", line 10, in <module>
#17 73.14         from collections import Sequence
#17 73.14     ImportError: cannot import name 'Sequence' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)
#17 73.14     ----------------------------------------
#17 73.14 WARNING: Discarding https://files.pythonhosted.org/packages/ac/aa/9b065a76b9af472437a0059f77e8f962fe350438b927cb80184c32f075eb/pathlib-1.0.1.tar.gz#sha256=6940718dfc3eff4258203ad5021090933e5c04707d5ca8cc9e73c94a7894ea9f (from https://pypi.org/simple/pathlib/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#17 73.14 ERROR: Could not find a version that satisfies the requirement pathlib==1.0.1 (from versions: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.97, 1.0, 1.0.1)
#17 73.14 ERROR: No matching distribution found for pathlib==1.0.1

I attempted to install the dependencies requirements.txt on my local machine and it ran without any issues, but when the docker image is built it errors

Docker file:

FROM python:3

WORKDIR /usr/src/app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 5010

RUN chmod u+x ./entrypoint.sh

requirements.txt:

alembic==1.7.3
aniso8601==8.0.0
appdirs==1.4.4
artifactory==0.1.17
attrs==20.3.0
bcrypt==3.2.0
beautifulsoup4==4.9.3
bidict==0.21.3
blinker==1.4
boto3==1.18.50
botocore==1.21.50
bs4==0.0.1
cachelib==0.3.0
certifi==2020.12.5
cffi==1.14.5
chardet==3.0.4
click==8.0.1
cryptography==3.4.6
distlib==0.3.2
dnspython==1.16.0
dominate==2.6.0
email-validator==1.1.3
et-xmlfile==1.1.0
eventlet==0.30.2
filelock==3.0.12
Flask==2.0.1
Flask-Bootstrap==3.3.7.1
Flask-Login==0.5.0
Flask-Mail==0.9.1
flask-marshmallow==0.14.0
Flask-Migrate==3.1.0
Flask-RESTful==0.3.8
Flask-Session==0.4.0
Flask-SocketIO==5.1.1
Flask-SQLAlchemy==2.5.1
Flask-User==1.0.2.2
Flask-WTF==0.15.1
greenlet==1.1.0
gunicorn==20.1.0
idna==2.10
iniconfig==1.1.1
is-safe-url==1.0
itsdangerous==2.0.1
Jinja2==3.0.1
jmespath==0.10.0
Mako==1.1.5
MarkupSafe==2.0.1
marshmallow==3.12.2
marshmallow-sqlalchemy==0.26.1
numpy==1.21.0
openpyxl==3.0.7
packaging==20.9
pandas==1.2.5
paramiko==2.7.2
passlib==1.7.4
pexpect==4.8.0
pluggy==0.13.1
psycopg2-binary==2.9.1
ptyprocess==0.7.0
py==1.10.0
pycparser==2.20
PyNaCl==1.4.0
pyparsing==2.4.7
pytest==6.2.3
python-dateutil==2.8.1
python-dotenv==0.19.0
python-engineio==4.2.1
python-socketio==5.4.0
pytz==2021.1
requests==2.24.0
s3transfer==0.5.0
scp==0.13.3
shippo==2.0.2
simplejson==3.17.2
six==1.15.0
soupsieve==2.2
SQLAlchemy==1.4.15
SQLAlchemy-Utils==0.37.8
toml==0.10.2
urllib3==1.25.11
virtualenv==20.4.7
visitor==0.1.3
Werkzeug==2.0.2
WTForms==2.3.3
XlsxWriter==1.4.3

I also tried just taking pathlib out of the requirements file so that the other dependencies could install it on their own, which attempted multiple versions of pathlib, but it still errored:

#9 86.72 ERROR: Could not find a version that satisfies the requirement pathlib (from artifactory) (from versions: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.97, 1.0, 1.0.1)
#9 86.72 ERROR: No matching distribution found for pathlib

Any help would be greatly appreciated.

like image 219
Lucas Rahn Avatar asked Nov 01 '25 05:11

Lucas Rahn


1 Answers

If you have a look for the base image, you could see it just be updated 27hours ago.

$ docker images python:3
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
python              3                   618fff2bfc18        27 hours ago        915MB

In fact, from its docker hub, the python:3 tag is now point to python 3.10.0, not python 3.9 days ago when you wrote your Dockerfile.

To get ride of any incompatibility issue caused by third-party library, you'd better to downgrade your base image to python 3.9 again:

FROM python:3.9
like image 105
atline Avatar answered Nov 03 '25 19:11

atline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!