Linux 系统中 NumPy (Python 2) 编程环境

1. Installation

strong@foreverstrong:~$ sudo apt-get install python-numpy

2. NumPy 版本

strong@foreverstrong:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> print(numpy.version)
<module 'numpy.version' from '/home/strong/.local/lib/python2.7/site-packages/numpy/version.pyc'>
>>> print(numpy.version.version)
1.13.3
>>> exit()
strong@foreverstrong:~$ 

3. NumPy 目录 - /home/strong/.local/lib/python2.7/site-packages/numpy/core/include

strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.get_include()
'/home/strong/.local/lib/python2.7/site-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$

4. NumPy 目录 - /usr/local/lib/python2.7/dist-packages/numpy/core/include

strong@foreverstrong:~$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.get_include()
'/usr/local/lib/python2.7/dist-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$

5. sudo pip install numpy

NumPy 目录 - /usr/local/lib/python2.7/dist-packages/numpy/core/include

strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.get_include()
'/home/strong/.local/lib/python2.7/site-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ sudo apt-get update
...
Reading package lists... Done
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ sudo apt-get install python-numpy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-numpy is already the newest version (1:1.11.0-1ubuntu1).
The following packages were automatically installed and are no longer required:
  gimp-data libamd2.4.1 libbabl-0.1-0 libcamd2.4.1 libccolamd2.9.1 libcholmod3.0.6 libgcrypt20:i386
  libgegl-0.3-0 libgimp2.0 libsystemd0:i386 libumfpack5.7.1
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 524 not upgraded.
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> print(numpy.version)
<module 'numpy.version' from '/home/strong/.local/lib/python2.7/site-packages/numpy/version.pyc'>
>>> print(numpy.version.version)
1.13.3
>>> exit()
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ sudo apt-get purge --auto-remove python-numpy
[sudo] password for strong: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  gimp-data* libamd2.4.1* libbabl-0.1-0* libcamd2.4.1* libccolamd2.9.1* libcholmod3.0.6* libgcrypt20:i386*
  libgegl-0.3-0* libgimp2.0* libjs-jquery-ui* libsystemd0:i386* libumfpack5.7.1* python-cycler*
  python-dateutil* python-decorator* python-joblib* python-matplotlib* python-matplotlib-data* python-nose*
  python-numpy* python-opencv* python-pyparsing* python-scipy* python-simplejson* python-sklearn*
  python-sklearn-lib* python-tz*
0 upgraded, 0 newly installed, 27 to remove and 521 not upgraded.
After this operation, 147 MB disk space will be freed.
...
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.get_include()
'/home/strong/.local/lib/python2.7/site-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ pip list
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
Package                            Version    
---------------------------------- -----------
adium-theme-ubuntu                 0.3.4      
attrs                              15.2.0     
...
notebook                           5.5.0      
numpy                              1.13.3     
olefile                            0.44       
...     
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ pip install numpy
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
Requirement already satisfied: numpy in ./.local/lib/python2.7/site-packages (1.13.3)
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$
 
strong@foreverstrong:~$ sudo pip uninstall numpy
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling numpy-1.13.3:
  Would remove:
    /home/strong/.local/bin/f2py
    /home/strong/.local/lib/python2.7/site-packages/numpy-1.13.3.dist-info/*
    /home/strong/.local/lib/python2.7/site-packages/numpy/*
Proceed (y/n)? y
  Successfully uninstalled numpy-1.13.3
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.get_include()
'/usr/local/lib/python2.7/dist-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ sudo pip uninstall numpy
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling numpy-1.13.3:
  Would remove:
    /usr/local/bin/f2py
    /usr/local/lib/python2.7/dist-packages/numpy-1.13.3.dist-info/*
    /usr/local/lib/python2.7/dist-packages/numpy/*
Proceed (y/n)? y
  Successfully uninstalled numpy-1.13.3
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> exit()
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ sudo pip install numpy
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/strong/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting numpy
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb926730a50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /packages/e0/b5/63b79fe426433fa1cd110eb04a94ec0c6967e56e5f57c98caf455a5fb6e2/numpy-1.16.1-cp27-cp27mu-manylinux1_x86_64.whl
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb926730ed0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /packages/e0/b5/63b79fe426433fa1cd110eb04a94ec0c6967e56e5f57c98caf455a5fb6e2/numpy-1.16.1-cp27-cp27mu-manylinux1_x86_64.whl
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb925c24310>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /packages/e0/b5/63b79fe426433fa1cd110eb04a94ec0c6967e56e5f57c98caf455a5fb6e2/numpy-1.16.1-cp27-cp27mu-manylinux1_x86_64.whl
  Downloading https://files.pythonhosted.org/packages/e0/b5/63b79fe426433fa1cd110eb04a94ec0c6967e56e5f57c98caf455a5fb6e2/numpy-1.16.1-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)
    100% |████████████████████████████████| 17.0MB 2.2MB/s 
Installing collected packages: numpy
Successfully installed numpy-1.16.1
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.get_include()
'/usr/local/lib/python2.7/dist-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$ 

6. sudo apt-get install python-numpy

NumPy 目录 - /usr/lib/python2.7/dist-packages/numpy/core/include

strong@foreverstrong:~$ pip uninstall numpy
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
Uninstalling numpy-1.16.1:
  Would remove:
    /usr/local/bin/f2py
    /usr/local/bin/f2py2
    /usr/local/bin/f2py2.7
    /usr/local/lib/python2.7/dist-packages/numpy-1.16.1.dist-info/*
    /usr/local/lib/python2.7/dist-packages/numpy/*
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/basecommand.py", line 141, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/commands/uninstall.py", line 74, in run
    auto_confirm=options.yes, verbose=self.verbosity > 0,
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/req/req_install.py", line 864, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/req/req_uninstall.py", line 221, in remove
    renames(path, new_path)
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/utils/misc.py", line 276, in renames
    shutil.move(old, new)
  File "/usr/lib/python2.7/shutil.py", line 303, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/local/bin/f2py'
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$
 
strong@foreverstrong:~$ sudo pip uninstall numpy
[sudo] password for strong: 
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling numpy-1.16.1:
  Would remove:
    /usr/local/bin/f2py
    /usr/local/bin/f2py2
    /usr/local/bin/f2py2.7
    /usr/local/lib/python2.7/dist-packages/numpy-1.16.1.dist-info/*
    /usr/local/lib/python2.7/dist-packages/numpy/*
Proceed (y/n)? y
  Successfully uninstalled numpy-1.16.1
The directory '/home/strong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python 
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> exit()
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ sudo apt-get update
...                                                                                
Reading package lists... Done
strong@foreverstrong:~$
 
strong@foreverstrong:~$ sudo apt-get install python-numpy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  python-nose python-numpy-dbg python-numpy-doc
The following NEW packages will be installed:
  python-numpy
0 upgraded, 1 newly installed, 0 to remove and 521 not upgraded.
Need to get 1,763 kB of archives.
After this operation, 9,598 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 python-numpy amd64 1:1.11.0-1ubuntu1 [1,763 kB]
Fetched 1,763 kB in 30s (57.5 kB/s)                                                                                               
Selecting previously unselected package python-numpy.
(Reading database ... 300164 files and directories currently installed.)
Preparing to unpack .../python-numpy_1%3a1.11.0-1ubuntu1_amd64.deb ...
Unpacking python-numpy (1:1.11.0-1ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python-numpy (1:1.11.0-1ubuntu1) ...
strong@foreverstrong:~$ 
 
strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.get_include()
'/usr/lib/python2.7/dist-packages/numpy/core/include'
>>> exit()
strong@foreverstrong:~$ 

7. fatal error: numpy/arrayobject.h: No such file or directory

出现 fatal error: numpy/arrayobject.h: No such file or directory 问题,请核实 makefile 中指定的 Python 路径与系统中实际的 Python 路径是否一致。

NumPy 目录 - /home/strong/.local/lib/python2.7/site-packages/numpy/core/include
sudo pip install numpy - NumPy 目录 - /usr/local/lib/python2.7/dist-packages/numpy/core/include
sudo apt-get install python-numpy - NumPy 目录 - /usr/lib/python2.7/dist-packages/numpy/core/include
strong@foreverstrong:~$ python -c "import numpy; print(numpy.get_include())"
/usr/lib/python2.7/dist-packages/numpy/core/include
strong@foreverstrong:~$
strong@foreverstrong:~$ python -c "import numpy; print(numpy.get_include())"
/home/strong/.local/lib/python2.7/site-packages/numpy/core/include
strong@foreverstrong:~$

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

相关推荐

  1. Linux 系统 NumPy (Python 2) 编程环境

    2024-03-23 05:50:07       18 阅读
  2. Linux 系统 OpenCV-Python 编程环境

    2024-03-23 05:50:07       21 阅读
  3. Linux系统编程_文件编程

    2024-03-23 05:50:07       13 阅读
  4. (五)Linux编程环境

    2024-03-23 05:50:07       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-23 05:50:07       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-23 05:50:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-23 05:50:07       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-23 05:50:07       20 阅读

热门阅读

  1. 【Android】App 屏幕适配方案

    2024-03-23 05:50:07       20 阅读
  2. 2024.3.22 ARM

    2024-03-23 05:50:07       17 阅读
  3. Promise和事件轮询

    2024-03-23 05:50:07       18 阅读
  4. Spring Boot单元测试

    2024-03-23 05:50:07       16 阅读
  5. Spring Boot集成chronicle queue快速入门demo

    2024-03-23 05:50:07       20 阅读
  6. 各大编程语言输出Hello World

    2024-03-23 05:50:07       22 阅读
  7. 在 CentOS 7 上编译安装 Nginx 1.18

    2024-03-23 05:50:07       22 阅读
  8. centos docker 安装es

    2024-03-23 05:50:07       16 阅读
  9. 在CentOS中怎么安装和配置NginxWeb服务器

    2024-03-23 05:50:07       18 阅读