python中每个模块都有一个名称,导入具有相同名称的python模块

I have several python projects and they all have a conf package:

/some_folder/project_1/

conf/

__init__.py

some_source_file.py

/another_folder/project_2/

conf/

__init__.py

another_source_file.py

For each project, I have created a .pth file in the site-packages folder with this contents:

.../site-packages/project_1.pth:

import sys; sys.path.append('/some_folder/project_1/')

.../site-packages/project_2.pth:

import sys; sys.path.append('/another_folder/project_2/')

I can access modules in /some_folder/project_1/:

import conf.some_source_file

but not the modules in /another_folder/project_2/:

import conf.another_source_file

AttributeError: 'module' object has no attribute 'another_source_file'

It looks as if python only searches the first conf path underneath any folders in sys.path. Is there a way to fix that ?

解决方案

No. You will need to either rename one of them or turn the project directory into a package and import via that.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值