当前位置:   article > 正文

pytorch-1.4.0-cpu安装_torch.__version__ = 1.4.0 traceback (most recent c

torch.__version__ = 1.4.0 traceback (most recent call last): file "setup.py

主要参考链接:

http://emanual.robotis.com/docs/en/platform/turtlebot3/machine_learning/#machine-learning
**

1、Anaconda2 安装

**
ROS 1中使用的是 python2.7,所以在地址:https://www.anaconda.com/download/#linux 中下载 python2.7版本的Anaconda2 ,安装过程如下:

chmod +x Anaconda2-5.2.0-Linux-x86_64.sh
 
bash Anaconda2-5.2.0-Linux-x86_64.sh
  • 1
  • 2
  • 3

安装完成后,执行下面指令, 如果可以看到 Python 2.7.xx :: Anaconda, Inc…,说明安装成功。

source ~/.bashrc
 
python -V
  • 1
  • 2
  • 3

接下来配置环境变量 PYTHONPATH,编辑 ~/.bashrc ,修改或者添加内容如下:

#export PYTHONPATH="/usr/lib/python2.7/dist-packages:$PYTHONPATH"
 
export PYTHONPATH="/home/wsc/anaconda2/lib/python2.7/dist-packages:$PYTHONPATH"
  • 1
  • 2
  • 3

2、 ROS 依赖包安装

pip install -U rosinstall msgpack empy defusedxml netifaces
  • 1

3、虚拟环境创建、pytorch安装

创建名为pytorch1的虚拟环境

conda create -n pytorch1 pip python=2.7
  • 1

进入或者离开虚拟环境的指令为:

# To activate this environment, use:
# > source activate tensorflow
#
# To deactivate an active environment, use:
# > source deactivate
  • 1
  • 2
  • 3
  • 4
  • 5

在虚拟环境中安装pytorch以及ROS依赖包:

source activate tensorflow
 
pip install -U rosinstall msgpack empy defusedxml netifaces

pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

完成后检验是否有错误:

    python
    import torch
    import torchvision

  • 1
  • 2
  • 3
  • 4

若没有报错则完成。

如果输入import torch出现以下情况:

>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lyd/anaconda2/envs/tensorflow/lib/python2.7/site-packages/torch/__init__.py", line 19, in <module>
    from ._six import string_classes as _string_classes
  File "/home/lyd/anaconda2/envs/tensorflow/lib/python2.7/site-packages/torch/_six.py", line 23, in <module>
    import builtins
ImportError: No module named builtins

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

则返回虚拟空间安装:

pip install future
  • 1

最后的 .bashrc 文件

source /opt/ros/kinetic/setup.bash
source /home/lyd/catkin_ws/devel/setup.bash

# added by Anaconda2 installer
export PATH="/home/lyd/anaconda2/bin:$PATH"
export PYTHONPATH="/home/wsc/anaconda2/lib/python2.7/dist-packages:$PYTHONPATH"
export SVGA_VGPU10=0
export TURTLEBOT3_MODEL=burger
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/370954
推荐阅读
相关标签
  

闽ICP备14008679号