系统:ubuntu bionic    TX2开发板  ARM架构

在开辟的虚拟环境中安装,开辟环境时,似乎自动继承了base下的python3.6.9,就没继续安装新版本的python

AI推荐的适配版本是numpy==1.19.5

安装numpy报错:

(yfhenv) robot@ubuntu:~/YFH$ python --version
Python 3.6.9
(yfhenv) robot@ubuntu:~/YFH$ source ~/yfhenv/bin/activate
(yfhenv) robot@ubuntu:~/YFH$ pip install numpy==1.19.5 --no-cache-dir
Collecting numpy==1.19.5
  Downloading https://files.pythonhosted.org/packages/51/60/3f0fe5b7675a461d96b9d6729beecd3532565743278a9c3fe6dd09697fa7/numpy-1.19.5.zip (7.3MB)
    100% |████████████████████████████████| 7.3MB 6.3MB/s 
Installing collected packages: numpy
  Running setup.py install for numpy ... error
    Complete output from command /home/robot/yfhenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-zc19oq7u/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-lmg7qu8n-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/robot/yfhenv/include/site/python3.6/numpy:
    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
    Processing numpy/random/_bounded_integers.pxd.in
    Processing numpy/random/_mt19937.pyx
    Traceback (most recent call last):
      File "/tmp/pip-build-zc19oq7u/numpy/tools/cythonize.py", line 59, in process_pyx
        from Cython.Compiler.Version import version as cython_version
    ModuleNotFoundError: No module named 'Cython'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/tmp/pip-build-zc19oq7u/numpy/tools/cythonize.py", line 235, in <module>
        main()
      File "/tmp/pip-build-zc19oq7u/numpy/tools/cythonize.py", line 231, in main
        find_process_files(root_dir)
      File "/tmp/pip-build-zc19oq7u/numpy/tools/cythonize.py", line 222, in find_process_files
        process(root_dir, fromfile, tofile, function, hash_db)
      File "/tmp/pip-build-zc19oq7u/numpy/tools/cythonize.py", line 188, in process
        processor_function(fromfile, tofile)
      File "/tmp/pip-build-zc19oq7u/numpy/tools/cythonize.py", line 64, in process_pyx
        raise OSError('Cython needs to be installed in Python as a module')
    OSError: Cython needs to be installed in Python as a module
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-zc19oq7u/numpy/setup.py", line 508, in <module>
        setup_package()
      File "/tmp/pip-build-zc19oq7u/numpy/setup.py", line 488, in setup_package
        generate_cython()
      File "/tmp/pip-build-zc19oq7u/numpy/setup.py", line 285, in generate_cython
        raise RuntimeError("Running cythonize failed!")
    RuntimeError: Running cythonize failed!
    
    ----------------------------------------
Command "/home/robot/yfhenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-zc19oq7u/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-lmg7qu8n-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/robot/yfhenv/include/site/python3.6/numpy" failed with error code 1 in /tmp/pip-build-zc19oq7u/numpy/

找到原因是缺少cython,安装cython

(yfhenv) robot@ubuntu:~/YFH$ pip list|grep Cython
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
(yfhenv) robot@ubuntu:~/YFH$ pip list | grep Cython
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
(yfhenv) robot@ubuntu:~/YFH$ pip install --force-reinstall cython
Collecting cython
  Downloading https://files.pythonhosted.org/packages/27/6b/7c87867d255cbce8167ed99fc65635e9395d2af0f0c915428f5b17ec412d/Cython-3.0.12-py2.py3-none-any.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 496kB/s 
Installing collected packages: cython
Successfully installed cython-3.0.12

再次安装numpy报错

(yfhenv) robot@ubuntu:~/YFH$ pip install numpy==1.19.5 --no-cache-dir
Collecting numpy==1.19.5
  Downloading https://files.pythonhosted.org/packages/51/60/3f0fe5b7675a461d96b9d6729beecd3532565743278a9c3fe6dd09697fa7/numpy-1.19.5.zip (7.3MB)
    100% |████████████████████████████████| 7.3MB 36kB/s 
Installing collected packages: numpy
  Running setup.py install for numpy ... error
    Complete output from command /home/robot/yfhenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-rqt03lff/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-ns8toow7-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/robot/yfhenv/include/site/python3.6/numpy:
    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:
    ------------------------------------------------------------
    ...
            for i in range(1, RK_STATE_LEN):
                self.rng_state.key[i] = val[i]
            self.rng_state.pos = i
    
            self._bitgen.state = &self.rng_state
            self._bitgen.next_uint64 = &mt19937_uint64
                                       ^
    ------------------------------------------------------------
    
    _mt19937.pyx:138:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of the value being assigned.
    Processing numpy/random/_bounded_integers.pxd.in
    Processing numpy/random/_mt19937.pyx
    Traceback (most recent call last):
      File "/tmp/pip-build-rqt03lff/numpy/tools/cythonize.py", line 235, in <module>
        main()
      File "/tmp/pip-build-rqt03lff/numpy/tools/cythonize.py", line 231, in main
        find_process_files(root_dir)
      File "/tmp/pip-build-rqt03lff/numpy/tools/cythonize.py", line 222, in find_process_files
        process(root_dir, fromfile, tofile, function, hash_db)
      File "/tmp/pip-build-rqt03lff/numpy/tools/cythonize.py", line 188, in process
        processor_function(fromfile, tofile)
      File "/tmp/pip-build-rqt03lff/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 '['/home/robot/yfhenv/bin/python3', '-m', 'cython', '-3', '--fast-fail', '-o', '_mt19937.c', '_mt19937.pyx']' returned non-zero exit status 1.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-rqt03lff/numpy/setup.py", line 508, in <module>
        setup_package()
      File "/tmp/pip-build-rqt03lff/numpy/setup.py", line 488, in setup_package
        generate_cython()
      File "/tmp/pip-build-rqt03lff/numpy/setup.py", line 285, in generate_cython
        raise RuntimeError("Running cythonize failed!")
    RuntimeError: Running cythonize failed!
    
    ----------------------------------------
Command "/home/robot/yfhenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-rqt03lff/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-ns8toow7-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/robot/yfhenv/include/site/python3.6/numpy" failed with error code 1 in /tmp/pip-build-rqt03lff/numpy/

找到原因 Cython (3.0.12)版本过高不适配numpy==1.19.5(这不得不吐槽还是 chatgpt 更胜一筹),降低cython版本到 0.29.24

(yfhenv) robot@ubuntu:~/YFH$ pip install cython==0.29.24

Collecting cython==0.29.24
  Downloading https://files.pythonhosted.org/packages/ec/30/8707699ea6e1c1cbe79c37e91f5b06a6266de24f699a5e19b8c0a63c4b65/Cython-0.29.24-py2.py3-none-any.whl (979kB)
    100% |████████████████████████████████| 983kB 45kB/s 
Installing collected packages: cython
  Found existing installation: Cython 3.0.12
    Uninstalling Cython-3.0.12:
      Successfully uninstalled Cython-3.0.12
Successfully installed cython-0.29.24
(yfhenv) robot@ubuntu:~/YFH$ 
(yfhenv) robot@ubuntu:~/YFH$ 

然后再安装numpy成功~

(yfhenv) robot@ubuntu:~/YFH$ pip install numpy==1.19.5 --no-cache-dir
Collecting numpy==1.19.5
  Downloading https://files.pythonhosted.org/packages/51/60/3f0fe5b7675a461d96b9d6729beecd3532565743278a9c3fe6dd09697fa7/numpy-1.19.5.zip (7.3MB)
    100% |████████████████████████████████| 7.3MB 23.3MB/s 
Installing collected packages: numpy
  Running setup.py install for numpy ... -

done
Successfully installed numpy-1.19.5
 

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐