Linux 系统中 NumPy [Python 2] 编程环境
- 1. Installation
- 2. NumPy 版本
- 3. NumPy 目录 - `/home/strong/.local/lib/python2.7/site-packages/numpy/core/include`
- 4. NumPy 目录 - `/usr/local/lib/python2.7/dist-packages/numpy/core/include`
- 5. sudo pip install numpy
- 6. sudo apt-get install python-numpy
- 7. fatal error: numpy/arrayobject.h: No such file or directory
- References
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:i386libgegl-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)? ySuccessfully 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)? ySuccessfully 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 numpyRetrying (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.whlRetrying (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.whlRetrying (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.whlDownloading 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 mainstatus = self.run(options, args)File "/usr/local/lib/python2.7/dist-packages/pip/_internal/commands/uninstall.py", line 74, in runauto_confirm=options.yes, verbose=self.verbosity > 0,File "/usr/local/lib/python2.7/dist-packages/pip/_internal/req/req_install.py", line 864, in uninstalluninstalled_pathset.remove(auto_confirm, verbose)File "/usr/local/lib/python2.7/dist-packages/pip/_internal/req/req_uninstall.py", line 221, in removerenames(path, new_path)File "/usr/local/lib/python2.7/dist-packages/pip/_internal/utils/misc.py", line 276, in renamesshutil.move(old, new)File "/usr/lib/python2.7/shutil.py", line 303, in moveos.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)? ySuccessfully 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/