如何使用 for 循环将多个 .so 文件导入 Python?
How could I import several .so files to Python with for loop?
所以我想导入子目录中的几个 .so
文件,这里是树
.
├── driver.py
├── intvegas.f
├── jetdrive-unp-algo.f90
├── jetint-unp-algo.f
├── jetme-unp-algo.f
├── makefile
├── part-unp-ms.f90
├── setup.sh
└── so
├── g_g_to_g_g.so
├── g_g_to_q_qb.so
├── g_q_to_g_q.so
├── q_q_to_q_q.so
├── q_qb_to_g_g.so
├── q_qb_to_q_qb.so
├── q_qb_to_qp_qbp.so
├── q_qbp_to_q_qbp.so
├── q_qp_to_q_qp.so
└── total.so
我想导入目录 so
中的所有 .so
文件,这是代码
#!/usr/bin/env python
import sys, os
sys.path.insert(0, './so')
import numpy as np
import pylab as py
channels = {'total', 'q_qp_to_q_qp', 'q_qbp_to_q_qbp', 'q_q_to_q_q', 'q_qb_to_qp_qbp', 'q_qb_to_q_qb', 'q_qb_to_g_g', 'g_g_to_q_qb', 'g_q_to_g_q', 'g_g_to_g_g'}
import importlib
for channel in channels:
module = './so' + channel
globals()[module] = importlib.import_module(module, package = 'my_current_package')
但我收到如下错误
ImportError: Import by filename is not supported.
谁能帮我解决这个问题?非常感谢!
for channel in channels:
module = './so' + channel
您确定在这种情况下获得了正确的文件名吗?
也许解决方法是:
module = channel
所以我想导入子目录中的几个 .so
文件,这里是树
.
├── driver.py
├── intvegas.f
├── jetdrive-unp-algo.f90
├── jetint-unp-algo.f
├── jetme-unp-algo.f
├── makefile
├── part-unp-ms.f90
├── setup.sh
└── so
├── g_g_to_g_g.so
├── g_g_to_q_qb.so
├── g_q_to_g_q.so
├── q_q_to_q_q.so
├── q_qb_to_g_g.so
├── q_qb_to_q_qb.so
├── q_qb_to_qp_qbp.so
├── q_qbp_to_q_qbp.so
├── q_qp_to_q_qp.so
└── total.so
我想导入目录 so
中的所有 .so
文件,这是代码
#!/usr/bin/env python
import sys, os
sys.path.insert(0, './so')
import numpy as np
import pylab as py
channels = {'total', 'q_qp_to_q_qp', 'q_qbp_to_q_qbp', 'q_q_to_q_q', 'q_qb_to_qp_qbp', 'q_qb_to_q_qb', 'q_qb_to_g_g', 'g_g_to_q_qb', 'g_q_to_g_q', 'g_g_to_g_g'}
import importlib
for channel in channels:
module = './so' + channel
globals()[module] = importlib.import_module(module, package = 'my_current_package')
但我收到如下错误
ImportError: Import by filename is not supported.
谁能帮我解决这个问题?非常感谢!
for channel in channels:
module = './so' + channel
您确定在这种情况下获得了正确的文件名吗? 也许解决方法是:
module = channel