简体   繁体   中英

Pip installing packages incompatible to Python version

I'm trying to install numpy using docker, but I get the following error:

 ---> Running in 9f2546faf5d7
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/c5/63/a48648ebc57711348420670bb074998f79828291f68aebfff1642be212ec/numpy-1.19.4.zip (7.3MB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-xoiwnjj7/numpy/setup.py", line 68
        f"NumPy {VERSION} may not yet support Python "
                                                     ^
    SyntaxError: invalid syntax
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-xoiwnjj7/numpy/
You are using pip version 8.1.1, however version 20.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip3 install numpy' returned a non-zero code: 1

Here is the Dockerfile:

from ubuntu:16.04

run apt-get update && apt-get install -y  \
python3-pip

run pip3 install \
numpy

The Python version is 3.5.2. The issue seems to be that the f-string syntax was only introduced in Python 3.6. It seems weird to me that pip is installing packages that are not compatible with my version of Python, especially since pip apparently doesn't install versions of packages that were released before the installed Python version. Is there an easy way to only install versions of packages that work with my version of Python?

Seems like this is an ubuntu 16.04 specific issue from this thread .

upgrade pip as root so pip can be upgraded if it is installed in some other locations.

To upgrade pip, run sudo python3 -m pip install --upgrade pip .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM