File “/tmp/pip-build-4bFKU6/numpy/setup.py“, line 27, in <module>——手动安装pip

博客详细记录了在Ubuntu18.04上由于依赖冲突无法安装Python2.7和numpy的问题。通过使用Docker拉取16.04镜像并配置环境,最终成功手动安装pip和numpy的过程,包括升级pip的困难以及解决方案。
摘要由CSDN通过智能技术生成

ubuntu18.04不能安装python2.7(依赖冲突),网上搜索了很多解决办法,并不好使。

直接使用docker pull一个新的ubuntu系统镜像并运行,配置环境

sudo docker pull paopaorobot/ubuntu-xfce-vnc:16.04
sudo docker run -it -p 5900:5900 -v [你想映射的目录]:/root/data paopaorobot/ubuntu-xfce-vnc:16.04

vnc viewer中链接5900,打开终端,cd到你映射的目录如/root/data,如下
在这里插入图片描述

在终端运行python2 associate.py rgb.txt depth.txt >> assoc.txt报错,提示

root@ecf60995ac42:~/data#   python2 associate.py rgb.txt depth.txt >> assoc.txt
Traceback (most recent call last):
  File "associate.py", line 46, in <module>
    import numpy
ImportError: No module named numpy

从仓库安装pip[不好使,建议手动安装]

apt-get update
apt install python-pip

使用pip安装,提示错误

root@ecf60995ac42:~/data# pip install numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/3a/be/650f9c091ef71cb01d735775d554e068752d3ff63d7943b26316dc401749/numpy-1.21.2.zip (10.3MB)
    100% |################################| 10.3MB 153kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-4bFKU6/numpy/setup.py", line 27, in <module>
        import builtins
    ImportError: No module named builtins
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4bFKU6/numpy/
You are using pip version 8.1.1, however version 21.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

pip install --upgrade pip也失败了

root@ecf60995ac42:~/data# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/52/e1/06c018197d8151383f66ebf6979d951995cf495629fc54149491f5d157d0/pip-21.2.4.tar.gz (1.6MB)
    100% |################################| 1.6MB 882kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-eSROaQ/pip/setup.py", line 7
        def read(rel_path: str) -> str:
                         ^
    SyntaxError: invalid syntax
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-eSROaQ/pip/
You are using pip version 8.1.1, however version 21.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

最后只能手动安装pip
官网下载get-pip.py文件,放置在sudo docker run -it -p 5900:5900 -v [你想映射的目录]:/root/data paopaorobot/ubuntu-xfce-vnc:16.04中你想映射的目录下(会自动同步到/root/data文件夹下),然后在上述vnc viewer中打开的终端中继续输入

python get-pip.py

如下安装成功

root@ecf60995ac42:~/data# python get-pip.py 
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pip<21.0
  Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
     |################################| 1.5 MB 1.2 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
Successfully installed pip-20.3.4

vnc viewer中重新打开一个终端(很重要,旧的终端文件系统未更新,会提示错误),然后运行

root@ecf60995ac42:~/data# pip install numpy
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting numpy
  Downloading numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
     |################################| 17.0 MB 288 kB/s 
Installing collected packages: numpy
Successfully installed numpy-1.16.6

最终成功

root@ecf60995ac42:~/data# python2 associate.py rgb.txt depth.txt >> assoc.txt
root@ecf60995ac42:~/data# 
Failed cleaning build dir for numpy Failed to build numpy Installing collected packages: numpy Running setup.py install for numpy ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-h5_vrlht/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-3koy23ws-record/install-record.txt --single-version-externally-managed --compile --user --prefix=: Running from numpy source directory. Note: if you need reliable uninstall behavior, then install with pip instead of using `setup.py install`: - `pip install .` (from a git repo or downloaded source release) - `pip install numpy` (last NumPy release on PyPi) Cythonizing sources Error compiling Cython file: ------------------------------------------------------------ ... cdef sfc64_state rng_state def __init__(self, seed=None): BitGenerator.__init__(self, seed) self._bitgen.state = <void *>&self.rng_state self._bitgen.next_uint64 = &sfc64_uint64 ^ ------------------------------------------------------------ _sfc64.pyx:90:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil' numpy/random/_bounded_integers.pxd.in has not changed Processing numpy/random/_sfc64.pyx Traceback (most recent call last): File "/tmp/pip-build-h5_vrlht/numpy/tools/cythonize.py", line 235, in <module> main() File "/tmp/pip-build-h5_vrlht/numpy/tools/cythonize.py", line 231, in main find_process_files(root_dir) File "/tmp/pip-build-h5_vrlht/numpy/tools/cythonize.py", line 222, in find_process_files process(root_dir, fromfile, tofile, function, hash_db) File "/tmp/pip-build-h5_vrlht/numpy/tools/cythonize.py", line 188, in process processor_function(fromfile, tofile) File "/tmp/pip-build-h5_vrlht/numpy/tools/cythonize.py", line 78, in process_pyx [sys.executable, '-m', 'cython'] + flags + ["-o", tofile, fromfile]) File "/usr/lib/python3.6/subprocess.py", line 311, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'cython', '-3', '--fast-fail', '-o', '_sfc64.c', '_sfc64.pyx']' returned non-zero exit status 1. Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-h5_vrlht/numpy/setup.py", line 508, in <module> setup_package() File "/tmp/pip-build-h5_vrlht/numpy/setup.py", line 488, in setup_package generate_cython() File "/tmp/pip-build-h5_vrlht/numpy/setup.py", line 285, in generate_cython raise RuntimeError("Running cythonize failed!") RuntimeError: Running cythonize failed! ---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-h5_vrlht/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-3koy23ws-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-h5_vrlht/numpy/
07-25
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值