我一直在尝试使用conda安装“ mkldnn”,但是遇到了“ conda已安装但python无法找到已安装的模块”这一老问题。奇怪的是,在我将路径添加到python import之后,它仍然找不到。
您碰巧知道为什么吗?这是我尝试过的方法和结果。
步骤1:我尝试使用Python3.6构建新的conda环境,并使用conda重新安装mkldnn
。仍然找不到。
[yl5090@log-0 ~]$ module purge
[yl5090@log-0 ~]$ module load anaconda3/5.3.0
[yl5090@log-0 ~]$ conda create --name pytorch-mpi python=3.6
Solving environment: done
## Package Plan ##
environment location: /home/yl5090/.conda/envs/pytorch-mpi
added / updated specs:
- python=3.6
The following NEW packages will be INSTALLED:
ca-certificates: 2018.03.07-0
certifi: 2018.11.29-py36_0
libedit: 3.1.20170329-h6b74fdf_2
libffi: 3.2.1-hd88cf55_4
libgcc-ng: 8.2.0-hdf63c60_1
libstdcxx-ng: 8.2.0-hdf63c60_1
ncurses: 6.1-he6710b0_1
openssl: 1.1.1a-h7b6447c_0
pip: 18.1-py36_0
python: 3.6.7-h0371630_0
readline: 7.0-h7b6447c_5
setuptools: 40.6.2-py36_0
sqlite: 3.25.3-h7b6447c_0
tk: 8.6.8-hbc83047_0
wheel: 0.32.3-py36_0
xz: 5.2.4-h14c3975_4
zlib: 1.2.11-h7b6447c_3
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate pytorch-mpi
#
# To deactivate an active environment, use:
# > source deactivate
#
[yl5090@log-0 ~]$ source activate pytorch-mpi
(pytorch-mpi) [yl5090@log-0 ~]$ conda install -c mingfeima mkldnn
Solving environment: done
## Package Plan ##
environment location: /home/yl5090/.conda/envs/pytorch-mpi
added / updated specs:
- mkldnn
The following NEW packages will be INSTALLED:
intel-openmp: 2019.1-144
mkl: 2019.1-144
mkldnn: 0.16.1-0 mingfeima
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(pytorch-mpi) [yl5090@log-0 ~]$ python
Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mkldnn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mkldnn'
>>>
第2步:我已经检查了此Python mkldnn
中没有sys.path
软件包。
>>> import sys
>>> sys.path
['', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python36.zip', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6/lib-dynload', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6/site-packages']
[yl5090@log-1 lab4]$ cd /home/yl5090/.conda/envs/pytorch-mpi/lib
[yl5090@log-1 lib]$ pwd
/home/yl5090/.conda/envs/pytorch-mpi/lib
[yl5090@log-1 lib]$ find . -type d -name "*mkldnn*" -print
[yl5090@log-1 lib]$
步骤3:我检查了conda安装的numpy的导入路径,但在该路径中找不到mkldnn
。
>>> import numpy
>>> import inspect
>>> inspect.getfile(numpy)
'/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6/site-packages/numpy/__init__.py'
[yl5090@log-1 lib]$ cd /home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6/site-packages/
[yl5090@log-1 site-packages]$ ls
certifi pip
certifi-2018.11.29-py3.6.egg-info pip-18.1-py3.6.egg-info
easy_install.py pkg_resources
mkl_fft __pycache__
mkl_fft-1.0.6-py3.6.egg-info README.txt
mkl_random setuptools
mkl_random-1.0.2-py3.6.egg-info setuptools-40.6.2-py3.6.egg-info
numpy wheel
numpy-1.15.4-py3.6.egg-info wheel-0.32.3-py3.6.egg-info
步骤4:我确实在/.conda/pkgs
目录中找到了一个mkldnn安装并将其添加到python导入路径中。但仍然无法从python导入它。
[yl5090@log-1 pkgs]$ ls /home/yl5090/.conda/pkgs | grep mkldnn
mkldnn-0.16.1-0
[yl5090@log-1 pkgs]$ cd mkldnn*
[yl5090@log-1 mkldnn-0.16.1-0]$ ls
include info lib share
(load in python...)
>>> path = "/home/yl5090/.conda/pkgs"
>>> import sys
>>> sys.path.insert(0, path)
>>> sys.path
['/home/yl5090/.conda/pkgs', '', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python36.zip', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6/lib-dynload', '/home/yl5090/.conda/envs/pytorch-mpi/lib/python3.6/site-packages']
>>> import mkldnn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mkldnn'
我现在能想到的剩下的原因是Python无法在没有.so
文件的情况下导入__init__.py
文件,但是我不确定这是否是解决此问题的正确方向。
最后,这是我发现的mkldnn
目录中的内容,不确定这是否是conda安装的内容。
[yl5090@log-1 mkldnn-0.16.1-0]$ ls
include info lib share
谢谢!