python 安装库报错 IOError: [Errno 2] No such file or directory: '/tmp/pip-build-qxKbBk/numpy/setup.py' 一个解决方法
尝试在 Ubuntu 环境中安装 python 库时报错:
$ pip install numpy
Collecting numpy
Downloading https://files.pythonhosted.org/packages/1c/8a/0db635b225d2aa2984e405dc14bd2b0c324a0c312ea1bc9d283f2b83b038/numpy-2.0.1.tar.gz (18.9MB)
100% |████████████████████████████████| 18.9MB 52kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
IOError: [Errno 2] No such file or directory: '/tmp/pip-build-qxKbBk/numpy/setup.py'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qxKbBk/numpy/
You are using pip version 8.1.1, however version 24.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
我的环境是 Ubuntu 官网上下载的 x86_64 平台 Ubuntu 16.04 Server 版:
$ uname -a
Linux ubuntu 4.4.0-186-generic #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
在未做任何修改之前,其默认安装的 Python 版本如下:
$ python --version
Python 2.7.12
$ python3 --version
Python 3.5.2
$ pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
原因:python 不再支持维护该版本的 python/pip,可以更新 python 或使用与 python 对应版本的 pip,这里更新 pip 来解决这个问题,由于当前问题下 pip 不能更新自身,只能先下载 pip 之后再自行安装。
解决方法,自行下载、更新 pip 工具,方法如下:
-
下载 pip,可以自行去如下链接中查找与自己 Python 版本相对应的
get-pip.py
脚本$ wget https://bootstrap.pypa.io/pip/3.5/get-pip.py --2024-08-03 10:47:36-- https://bootstrap.pypa.io/pip/3.5/get-pip.py Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.192.175, 151.101.128.175, 151.101.64.175, ... Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.192.175|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1908223 (1.8M) [text/x-python] Saving to: ‘get-pip.py’ get-pip.py 100%[===========================================================================================>] 1.82M 733KB/s in 2.5s 2024-08-03 10:47:40 (733 KB/s) - ‘get-pip.py’ saved [1908223/1908223]
-
使用如下命令执行刚才下载的
get-pip.py
脚本,下载并更新自己环境中的 pip$ python3 get-pip.py DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality. Defaulting to user installation because normal site-packages is not writeable Collecting pip<21.0 Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB) |████████████████████████████████| 1.5 MB 1.4 MB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 24.2 Uninstalling pip-24.2: Successfully uninstalled pip-24.2 Successfully installed pip-20.3.4
在提示安装成功之后,可以查看到新的版本如下:
$ pip --version pip 20.3.4 from /home/arvin/.local/lib/python3.5/site-packages/pip (python 3.5) $ pip3 --version pip 20.3.4 from /home/arvin/.local/lib/python3.5/site-packages/pip (python 3.5) $ pip3.5 --version pip 20.3.4 from /home/arvin/.local/lib/python3.5/site-packages/pip (python 3.5)
现在,可以使用新的 pip 工具安装与环境 Python 版本匹配的库了,下面给出使用示例:
$ pip install paramiko
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting paramiko
Downloading paramiko-2.12.0-py2.py3-none-any.whl (213 kB)
|████████████████████████████████| 213 kB 192 kB/s
Collecting pynacl>=1.0.1
Downloading PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl (961 kB)
|████████████████████████████████| 961 kB 331 kB/s
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from paramiko) (1.10.0)
Collecting bcrypt>=3.1.3
Downloading bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl (56 kB)
|████████████████████████████████| 56 kB 13.4 MB/s
Collecting cryptography>=2.5
Downloading cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl (2.6 MB)
|████████████████████████████████| 2.6 MB 9.7 MB/s
Collecting cffi>=1.1
Downloading cffi-1.15.1.tar.gz (508 kB)
|████████████████████████████████| 508 kB 8.6 MB/s
Collecting pycparser
Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
|████████████████████████████████| 118 kB 8.2 MB/s
Building wheels for collected packages: cffi
Building wheel for cffi (setup.py) ... done
Created wheel for cffi: filename=cffi-1.15.1-cp35-cp35m-linux_x86_64.whl size=325277 sha256=0111afda98c4b69c69b9adc760507d571b4a238991fa9eeaef5c932a5f6e54f6
Stored in directory: /home/arvin/.cache/pip/wheels/1f/f8/f8/ec0358d5e26bed317d3979b984d9cbf45be68aae97d2fbe073
Successfully built cffi
Installing collected packages: pycparser, cffi, pynacl, cryptography, bcrypt, paramiko
Successfully installed bcrypt-3.1.7 cffi-1.15.1 cryptography-3.2.1 paramiko-2.12.0 pycparser-2.21 pynacl-1.4.0