Linux中vectormath无法通过pip安装的解决办法

在使用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 --user option 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'>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值