问题起因:
在根目录下python;import torch;未报错,表示pytorch可用
而进入虚拟环境目录python;import torch;报错如下:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'torch'
研究原因:
安装anaconda后:
ubuntu@ubuntu:~$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
表示未启用anaconda
输入
source ~/.bashrc (即重新执行刚修改的初始化文件,使之不需要重新登陆而立即生效)
重新
ubuntu@ubuntu:~/$ python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
则表示成功启用。
问题解决。