模块与单个.py文件的区别,模块中含有__init__.py文件,其中函数调用使用的是相对路径,如果使用导入.py文件的方法在Google Colab中导入模块

会报错:Attempted relative import in non-package

在Google Colab导入中导入一个本地模块

例,将pykalman模块导入,github地址  https://github.com/pykalman/pykalman

1.递归创建目录

!mkdir -p pykalman-master/pykalman

 

2.保存cell的内容到一个外部文件

%%writefile pykalman-master/pykalman/__init__.py
将__init__.py的内容复制进cell中

同理

%%writefile pykalman-master/pykalman/standard.py

······

%%writefile pykalman-master/pykalman/unscented.py

······

%%writefile pykalman-master/pykalman/utils.py

······

3.将pykalman-master目录添加到路径集合中

import sys
sys.path.append('pykalman-master')

  

4.导入新模块并调用其中的函数

from pykalman import KalmanFilter

  

在Google Colab导入中导入一个.py文件

例,定义example.py调用其中函数f():显示"Hello Python"

1.保存cell的内容到一个外部文件

%%writefile example.py
def f():
print 'Hello Python.'

  

2.将文件带入本地Python环境

execfile('example.py')

f()

  

最新文章

  1. 连接池的实现 redis例子
  2. store前台数据过滤
  3. rowcount和@@Rowcount的区别,获取insert、update、delete影响行数
  4. 如何查询MySql日志
  5. Mysql-学习笔记(==》连接查询_高级查询五)
  6. 206. Reverse Linked List
  7. atprogram.exe : Atmel Studio Command Line Interface
  8. qtp不识别树结构中的点击事件
  9. ASP.NET MVC 第六回 过滤器Filter
  10. Configuring the JA-SIG CAS Client --官方
  11. MongoDB(三)mongoDB下载和安装
  12. 连载:面向对象的葵花宝典:思维、技能与实践(40) - DECORATOR模式
  13. HDU 2073 无限的路
  14. CentOS安装glibc-2.14,错误安装libc.so.6丢失急救办法
  15. Can't update: no tracked branch No tracked branch configured for branch dev.
  16. instanceof的用法
  17. Makefile中的%标记和系统通配符*的区别
  18. Delphi2010分 AnsiChar(1个字节) 和WideChar(2个字节) 。D7都是AnsiChar。
  19. 使用java调用fastDFS客户端进行静态资源文件上传
  20. odoo创建编号

热门文章

  1. hihoCoder挑战赛27题目一 福字 (dp)
  2. JMeter设置Http代理对web或者app进行录制
  3. pg数据库表接口和数据导出
  4. 字符串(string+StringBuilder) +正则表达式元字符
  5. mongodb数据文件结构——record是内嵌BSON的双向链表,多个record或索引组成extent
  6. linux 部署python
  7. 剑指offer--15.把字符串转换成整数
  8. canvas基础学习(一)
  9. python whl包的安装
  10. Jupyterhub Error 503: Proxy Target Missing