无法导入python generated.so in python

2024-10-03 06:30:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我搜索了很多关于ImportError: No module named错误的讨论,但是似乎没有人能解决我的问题,所以请允许我再次询问。在

以下是我的包文件夹结构:

/modules
├── build
│   ├── lib.linux-x86_64-2.7
│   │   └── Package
│   │       ├── __init__.so
│   │       ├── SendTraffic.so
│   │       └── Utils.so
│   └── temp.linux-x86_64-2.7
│       └── Package
│           ├── __init__.o
│           ├── SendTraffic.o
│           └── Utils.o
├── Package
│   ├── __init__.py
│   ├── SendTraffic.c
│   ├── SendTraffic.py
│   ├── SendTraffic.pyc
│   ├── Utils.c
│   ├── Utils.py
│   └── Utils.pyc
├── setup.py

以及设置.py在

^{pr2}$

它可以成功地生成.so文件。但是当我在/modules/build/lib.linux-x86_64-2.7下导入它们时:

/modules/build/lib.linux-x86_64-2.7$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information. 
>>> import Package.SendTraffic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Package.SendTraffic

在包文件夹中,我可以成功导入它们:

/modules/build/lib.linux-x86_64-2.7/Package$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import SendTraffic
>>>

我也尝试过将/modules/build/lib.linux-x86_64-2.7添加到搜索路径,但不起作用。使用setup.py install将它们安装到系统范围的包文件夹中也不起作用。在

有人能帮我进口吗Package.SendTraffic成功了吗?在


Tags: nopybuild文件夹modulespackagesoinit