python2.7和3.4有什么区别_python3.4和python2.7中导入模块的区别

我试图导入另一个文件夹中的包,它在python3.4中运行得非常好。例如:这些文件存在于libraries文件夹中user> python

Python 3.4.1 (default, Nov 12 2014, 13:34:29)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> from libraries.controller_utils import *

>>>

但是,当我打开一个新的shell并使用python2.7时:

^{pr2}$

我尝试将条目添加到sys.path中,但没有帮助。我读过一个类似的问题here,但是这个解决方案对我也没有帮助,因为我尝试了相对和绝对导入。请指教。在

编辑:目录结构是~/tests/libraries/controller_utils.py。我在tests目录中执行这些命令。在

编辑:我添加了系统路径输入如下,但仍无法识别。请注意,错误发生在2.7版本,但在3.4版本中运行得非常好user> cd ~/tests/

user> ls

__pycache__ backups inputs libraries openflow.py test_flow.py

user> ls libraries/

__pycache__ controller_utils.py general_utils.py general_utils.pyc tc_name_list.py test_case_utils.py

user> python

Python 2.7.4 (default, Jun 1 2015, 10:35:58)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from libraries.controller_utils import *

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named libraries.controller_utils

>>> import sys

>>> sys.path.append('libraries/')

>>> from libraries.controller_utils import *

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named libraries.controller_utils

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值