本人是奇葩,最近鼓捣了一套在mac上coding远程ubuntu上的theano代码的东东,记之以期造福后人。

Overview: 下图是我的编程环境和网络环境

我期望能在本地mac机器上对远程的ubuntu theano server进行write、run、debug、view matplotlib图片。

mac设置(参考这里

考虑到在Mac本地调试一部分代码,我把mac也设置好了科学计算环境。

1.1 python

mac安装xcode后会自带很多东西,python就是其中一个。但mac提供的python版本不高,语法与标准python有区别。我使用brew安装了brewed python。

First install homebrew. Follow their instructions, then come back here.

# set up some taps and update brew 打开隐藏的科学库和python库

brew tap homebrew/science # a lot of cool formulae for scientific tools

brew tap homebrew/python # numpy, spicy

brew update && brew upgrade

# install a brewed python

brew install python

⚠brew安装的东西都在/usr/local/下,比如bin lib等。用which查看brew的python在/usr/local/bin下,mac自带的python 在/usr/bin下,/usr/local/bin should appear in front of /usr/bin。brew的package比如numpy会安装在local/python/site-package下。brew install python 会安装新的pip到local目录。以后brew的需要against brewed python lib的新软件比如macvim,会自动从$PATH中找第一个出现的python的lib。在ipython下,import os, print(os.path)可以看到$PYTHONPATH的路径,这个路径表示了使用哪个python。import numpy后,print numpy.___path__可以看到import的是哪个路径下的numpy。

# install numpy and scipy

brew install numpy 

brew install scipy

1.2  ipython

brew install qt pyqt 

# test the numpy & scipy install

brew test numpy

brew test scipy
#画图的

brew install matplotlib

# ipython and notebook support

brew install zmq

pip install ipython[zmq,qtconsole,notebook,test]

1.3 x11

A version of the X.Org X Window System that runs on OS X

x11是一个图形系统,ubuntu就是用x11来显示图形界面,pyhton的matplotlib也可以用x11,也可以用agg在不启动x11的时候使用plot,参考这里。mac有自己的一套图形界面,但也提供了x11支持(参考这里)。

2. 远程ubuntu12.04设置

2.1 theano、python、ipython的安装,(参考theano官方)

2.2 编译安装vim7.4+python版本,参考这里,⚠我几次编译都没能加入python支持,后来没有在编译时选装--enable-perlinterp \ --enable-luainterp \ --enable-gui=gtk2 --enable-cscope —prefix=/usr 这三个组件 才成功加入python支持,很奇怪,我猜是luain的原因。

2.3 youcompleteme安装,参考官方

3. mac与ubuntu互联互通

我在mac上通过ssh到ubuntu上用vim写python代码。调试时我希望能在mac上通过远程连接ubuntu的ipython的pdb

来调试。调试方法参考这里。问题是如何建立到远程python的链接呢?ipython的分离式设计给我提供了机会,参见下图。

ipython分成了kernel和frontend前端界面两个独立的部分。kerner可以运行在ubuntu上,而frontend可以运行在mac上。

3.1 方法1,在mac上用qtconsole连接远程kernel(请参考1 2

ubuntu端:

在ubuntu上启动ipython kernel,并绑定到ip,这样kernel就在192.168.2.6的41746 52697 52331 33016 58260这5个port上提供服务了。

server > ipython qtconsole —ip=192.168.2.6

这里也可以用ipython kernel来启动,但这时就木有x11或者agg支持了。

启动后在ipython中使用命令%connect_info来查看连接信息。

{

  "stdin_port": , 

  "ip": "192.168.2.6", 

  "control_port": , 

  "hb_port": , 

  "signature_scheme": "hmac-sha256", 

  "key": "8c035c48-3fd1-4492-801d-aad6bda49293", 

  "shell_port": , 

  "transport": "tcp", 

  "iopub_port": 

 }

启动后会自动生成一个如上内容的文件,这个文件可以在如下目录中找到

congliu@CUDA:~$ ls .ipython/profile_default/security/kernel-.json  kernel-.json  kernel-.json

mac端:

copy连接文件到本地

scp -P  congliu@61.61.61.61:/home/congliu/profile_default/security/kernel-.json ./

启动frontend,连接到防火墙61.61.61.61后面的192.168.2.6。其实是用ssh的端口映射功能先把mac上qtconsole对127.0.0.1的41746 52697 52331 33016 58260这5个port的访问forwarding到远方的192.168.2.6的相应端口上,因为ubuntu在firewall后面,所以还用到了ssh tunnel把mac和61.61.61.61连起来。

[congliu@CongLius-MacBook-Pro~]$ipython qtconsole --ssh=congliu@61.61.61.61:  --ip=192.168.2.6 --existing ./kernel-.json

3.2 方法2 ,在mac上用notebook连接远程kernel(请参考这里)

3.3 方法3,使用ssh的x11 forwarding 功能(请参考这里

ssh还真是强大,可以把本该在ubuntu上通过x11显示图形,forward到mac上显示,当然前提是mac上要装好x11的服务(参考这里)。在ubuntu的命令行中输入ipython qtconsole就是在mac上打开一个qtconsole。此时,mac上的python和ipython根本没有运行,mac上的x11就是从ubuntu上的x11接收指令然后显示在本地而已。ubuntu上同时运行了ipython的kernel和frontend。

Coding theano under remote ubuntu server from local Mac (在本地mac机器上,写、跑、调试、看-远程ubuntu上的theano代码)的更多相关文章

  1. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(三):设置上传文件夹权限(这里测试用完全共享)

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

  2. 解决Ubuntu Server 12.04换了网卡MAC地址后 网络不可用的问题.

    重装了系统,新建了一个ubuntu虚拟机,加载原来的镜像,结果启动后网络变得不正常了,提示信息 Waiting for network configuration...Waiting up to 60 ...

  3. ubuntu server安装OVS

    安装 Open vSwitch (Ubuntu Server 16.04)  1.查看主机系统内核版本:uname –a 2.上传openvswitch软件包,解压后执行安装: 更新下载源 $ sud ...

  4. 实战Ubuntu Server上配置LXDE+VNC环境

    1.安装x-window 使用apt-get 安装 xorg sudo apt-get install xorg 如果提示以下内容,就说明需要update下源列表,使用sudo apt-get upd ...

  5. [转]ubuntu server上网配置

    [转]ubuntu server上网配置 http://blog.sina.com.cn/s/blog_6c9d65a101011pyt.html 今天我的ubuntu server上不去网了,所以重 ...

  6. ubuntu server配置xmanager

    ubuntu server配置xmanager   ubuntu是典型的多用户多任务操作系统,通过XDMCP方式可以轻松的实现远程的多用户同时登录ubuntu任务.   www.2cto.com   ...

  7. ubuntu server 14.04.4 无线网卡没有启用,找不到wlan0端口

    Ubuntu Server默认的情况下是不会启用无线网卡的,想想实际服务器上怎么可能有无线网卡呢,呵呵.所以我们需要手动来启用无线网卡,难点就在这里了. 使用ifconfig命令,发现没有wlan口, ...

  8. ubuntu server 14.04 LTS下搭建LAMP环境之最详细笔记之一U盘安装双系统

    前言: 一直在WIN上使用PHP,不喜欢用WAMP,每次都是手动在windows配置环境,偶尔有一次装了小红帽玩了两天,感觉不是很习惯就换了回来,过了没几天见讨论LAMP环境,于是安装了ubuntu的 ...

  9. Ubuntu Server+openerp

    转自:http://www.2cto.com/os/201212/180118.html 今天主要完成OPENERP部署的第一步,安装Ubuntu Server操作系统: 1.将计算机的BIOS设定成 ...

随机推荐

  1. [WinForm]动态显示本地目录图片与悬浮窗

    加载显示: if (File.Exists(@"D:\产品图片\" + item + ".jpg")) { //需要判断是否存在图片 Image img = I ...

  2. 《java入门第一季》之面向对象面试题(fianl关键字)

    /* 面试题:final修饰局部变量的问题 基本类型:基本类型的值不能发生改变. 引用类型:引用类型的(地址值)(不能发生改变),但是,该对象的堆内存的值是可以改变的. */ class Studen ...

  3. Cocos2d中update与fixedUpdate的区别(三)

    没错!现在的情况是很糟糕.因为玩家不会看到平滑的动作. 不管怎样,我们都对此无能为力.玩家期待在1秒后小球出现在位置(8),所以我们应该把球放在那里. 我们不会讨论如何避免掉帧的情况.对于这个例子我们 ...

  4. Android平台根目录文件

    > 系统分区 # adb shell # mount rootfs / rootfs ro 0 0 tmpfs /dev tmpfs rw,mode=755 0 0 devpts /dev/pt ...

  5. Android进阶(十八)AndroidAPP开发问题汇总(二)

    Android进阶(十八)AndroidAPP开发问题汇总(二) 端口被占用解决措施: Android使用SimpleAdapter更新ListView里面的Drawable元素: http://ww ...

  6. RPi Kernel Compilation

    Overview This page explains how to rebuild the kernel image for the RPi. There are two possible rout ...

  7. Netfilter的使用和实现

    本文主要内容:Netfilter的原理和实现浅析,以及示例模块. 内核版本:2.6.37 Author:zhangskd @ csdn blog 概述 Netfilter为多种网络协议(IPv4.IP ...

  8. iOS中获取本地通讯录联系人以及汉字首字母排序

    iOS中获取手机通讯录中的联系人信息: /*** 加载本地联系人*/ - (void)loadLocalContacts { //新建一个通讯录类 ABAddressBookRef addressBo ...

  9. linux设备驱动模块引用和依赖

    /modules/04 # lsmod test 787 0 - Live 0xbf010000 (PO) func 633 1 test, Live 0xbf00c000 (PO) test -&g ...

  10. LeetCode(37)-Minimum Depth of Binary Tree

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...