在使用pip安装vectormath的时候
$ pip install vectormath
总是会报错
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: /usr/local/lib/python2.7/dist-packages/vectormath
/home/kai/.local/lib/python2.7/site-packages/pip/_vendor/requests/init.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
warnings.warn(warning, RequestsDependencyWarning)
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting vectormath
Requirement already satisfied: numpy>=1.7 in ./.local/lib/python2.7/site-packages (from vectormath) (1.16.4)
Installing collected packages: vectormath
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/usr/local/lib/python2.7/dist-packages/vectormath’
Consider using the--useroption or check the permissions.
解决办法:
去官网直接下载python文件,然后使用suso拷贝/usr/local/lib/python2.7/dist-packages/vectormath到这个目录中
具体步骤如下:
step1:下载python文件
官网直达链接:vectormath · PyPI
https://pypi.org/project/vectormath/#files

step2:创建安装目录
$ cd /usr/local/lib/python2.7/dist-packages/
$ sudo mkdir vectormath
step3:移动vectormath文件
解压缩得到如下所示,这里的setup.py运行仍然是没有用的,很失望。

然后进入vectormath文件夹

将这两个文件移动到/usr/local/lib/python2.7/dist-packages/vectormath这个目录中
$ sudo cp __init__.py vector.py /usr/local/lib/python2.7/dist-packages/vectormath
step4:测试一个test_vectormath.py
$ gedit test_vectormath.py
输入
import numpy as np
import vectormath as vmath
# Single Vectors
v = vmath.Vector3(5, 0, 0)
v.normalize()
print(v) # >> [1, 0, 0]
print(v.x) # >> 1.0
# VectorArrays are much faster than a for loop over Vectors
v_array = vmath.Vector3Array([[4, 0, 0], [0, 2, 0], [0, 0, 3]])
print(v_array.x) # >> [4, 0, 0]
print(v_array.length) # >> [4, 2, 3]
print(v_array.normalize()) # >> [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
# Vectors can be accessed individually or in slices
print(type(v_array[1:])) # >> vectormath.Vector3Array
print(type(v_array[2])) # >> vectormath.Vector3
# All these classes are just numpy arrays
print(isinstance(v, np.ndarray)) # >> True
print(type(v_array[1:, 1:])) # >> numpy.ndarray
然后关闭保存运行:
$ python test_vectormath.py
正常运行的话会显示这些:
[1. 0. 0.]
1.0
[4. 0. 0.]
[4. 2. 3.]
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
<class 'vectormath.vector.Vector3Array'>
<class 'vectormath.vector.Vector3'>
True
<type 'numpy.ndarray'>

博客讲述了vectormath安装时出现权限不足等报错情况,如‘Permission denied’等,还提示Python 2.7将不再被支持。给出的解决办法是去官网下载python文件,详细步骤包括下载文件、创建安装目录、移动vectormath文件以及测试test_vectormath.py。
30万+

被折叠的 条评论
为什么被折叠?



