Installing IVy
最合适的系统应该是ubuntu系统,且需要sudo权限。
windows和macosx系统会有诸多的限制,可能会和系统的版本不兼容导致无法运行图形界面,只能使用命令行。
本文介绍一下摸索的艰难历史。最终在mac系统下只能安装成功命令行,并且对于macosx 10.14 version, 目前图形界面是无法运行的。浪费了很多时间,真的是很不值得。记录下来,希望大家不要做无用功。
有三种方法可以安装ivy,分别是:
- Install a binary release
- Install from source in a virtual environment with Vagrant
- Install from source
主页:http://microsoft.github.io/ivy/install.html#vagrant
Method 1. Installing a release
Binary releases of IVy are available on IVy’s Github release page.
Linux
最方便的安装方式,直接下载、安装即可。记得要有sudo权限,否则安装失败。
On Debian-based linux ditributions such as Ubuntu, download and install the file ms-ivy_X.X_YYYY.deb
where X.X
is the IVy version and YYYY
is the machine architecture. Use your system’s package manager to install this package, or the following commands:
1 | $ sudo dpkg -i ms-ivy_X.X_YYYY.deb |
The first command will report missing dependencies, which will be installed by the second command.
Windows
windows 下载zip包之后,解压。在32位和64位电脑上都可以。
直接使用命令行,那么直接激活就行。
The Windows binary distribution is in the form of a zip archive. Download the file ivy.X.Y-.Windows-z86.zip
, where X.X
is the IVy version (this will work on both 32-bit and 64 bit Intel Windows). Use Windows Explorer to extract this archive in the directory C:\
. This should give you a directory C:\ivy
. To use IVy in a command window, first execute this command:
1 | > C:\ivy\scripts\activate |
这个方法可以激活一个虚拟环境,不过是命令行的。图形界面无法使用。
Mac
Mac下还没有可用的binary release,要用另外两种方法。
Method 2. Installing in a virtual environment with Vagrant
方法2是直接安装一个虚拟环境vagrant。
Windows
windows下就是直接用虚拟机virtualbox来跑。
On Windows, Virtualbox is currently the recommended container provider.
- Clone the
IVy
repository (e.g.git clone https://github.com/Microsoft/ivy.git
). - Download and install Vagrant.
- Download and install Virtualbox.
- Type
vagrant plugin install vagrant-vbguest
to install thevagrant-vbguest
plugin (optional but recommended). - Download and install an X11 server for Windows (e.g. Xming).
- Type
vagrant up
from an administrator console to prepare a new development environment. This is likely to take some time to complete the first time it is done, because z3 must be compiled from its sources. - Launch your X11 server and type
vagrant ssh
in a console window to get access to IVy from a shell within the container.
Linux
On Linux, Docker is also available as a container provider, and will yield better performance than the Virtualbox backend.
- Clone the
IVy
repository (e.g.git clone https://github.com/Microsoft/ivy.git
). - Install Vagrant.
- Install Docker.
- (Debian-based systems) Ensure your user is in the
docker
group. - Type
vagrant up --provider=docker
. - Type
vagrant ssh
to get access to IVy from a shell.
Linux users also have the option of directly executing the provisioning scripts in the scripts/setup
directory, bypassing any inconvenience a container might impose. The scripts are divided in such a way as to facilitate this. Those interested should take note, however, that the scripts have only been tested with Ubuntu and Debian Vagrant guest images so far.
MacOS
使用方法不稳定,与版本不兼容。所以这个方法在mac上也无法适用。
Method 3. Installing from source
Prerequisites
Python 2.7
注意,这个版本很重要,因为其他版本的安装有问题。2.7.x都可以,但是2的其他subversion就不行,很迷醉。(因为z3指定了要用py2.7)
Get it from here or as part of your Linux distribution. You should make sure to get the pip
utility. This is standard on versions from 2.7.9.
You can install IVy in a python virtual environment if you don’t want to pollute your local python setup. If you want to use a virtual environment, do the following before following the remaining installation instructions:
1 | $ pip install virtualenv |
这个启动之后,之后的安装都是在(ivy_env) 的这个虚拟环境下安装的。也可以不激活这个虚拟环境,不激活的话相当于你在本机上直接安装;虚拟环境下安装则不影响本机原先的环境变量。
Z3
z3是一个定理证明器,ivy依赖于z3,所以需要安装z3.
请注意!! z3 只能支持在python2.7的版本下运行,所以一定一定要注意!!尽管有的时候z3也能在python3.x的版本下import成功,但是跑出来的结果是不一样的,或无法出结果,说明在py3上的性能和支持还是不稳定,会浪费很多时间。
安装方式: here
安装成功测试:
1 | $ python |
看看是否能import成功,如果可以的话则说明成功。也可以运行z3里面的例子直接试试看。
如果想要安装z3在刚刚新建的ivy_env的虚拟环境下,则在安装z3的时候注明前缀:
1 | $ make install PREFIX=/path/to/ivy_env |
这个虚拟环境的路径,其实就是刚刚新建的那个ivy_env的那个环境的路径。
Python packages
要安装的python包包括: ply
, pygraphviz
and tarjan
.
On Ubuntu:
1 | $ sudo apt-get install python-ply python-pygraphviz |
如果只用ivy 命令行的话, 可以不用安装python-pygraphviz
,这个是用来交互地显示图形界面的。
注意版本:
Make sure you get version 3.4 of python-ply as some later versions are broken.
As an alternative, pip
can install all the packages, but you need to make sure the dependencies on system packages are met:
1 | $ sudo apt-get install graphviz graphviz-dev python-dev |
This latter is the option if you are making a virtual environment.
Tcl/Tk/Tix
这几个包是用来显示交互界面的,如果只打算用命令行,则这一步可以跳过。(macosx 10.14以上目前是无法成功安装这些包的,就算显示安装成功,也无法正常使用,请一定注意,不要在这里浪费时间!目前macosx 10.14以上版本无法使用ivy的图形界面!)
ubuntu
1 | $ sudo apt-get install python-tk tix |
This step is not necessary if using the IVy command line tools only.
mac
尽管在v-10.14下无法正常使用,但是还是记录一下自己的摸索过程,为更低级版本的mac系统更好的使用。
安装的版本也很重要,因为tcl 4.x, tk 4.x 和tix 6.x 是无法兼容的。这个一开始我还不相信,后来发现这几个版本是无法兼容的,所以不要一味下载最新的版本,它们是不兼容的,也安装不成功。
以下的步骤,请一定要按照顺序、版本来安装。是可以安装成功的,但是无法成功运行。这个就是mac系统与这些库还无法兼容的原因。
注意:
以下安装包的安装路径,一定不要包括奇怪的字符,如空格、中文等,不然安装时的make会无法成功,之后处理起来也很麻烦!
Install xQuartz
这个直接安装就行,是为之后tix做准备的
Install tcl 8.5.0
http://www.tcl.tk/software/tcltk/download.html 这里能下载最新版本
https://sourceforge.net/projects/tcl/files/Tcl/ 在这里能找到各个版本
请注意,最好下载8.5.0,其他的更高版本,试用了之后发现各种问题。下载、解压之后:
1 | cd tcl8.5.0/unix |
注意:
configure
后面的--enable-shared
是为了让这个tcl可以被之后的tk用到如果想安装在虚拟环境下,则需要在
configure
之后加上--prefix=/path/to/ivy_env
make
想加速的话,在后面加上-j 2
或者其他更大的数字,用来指定几核make最后的
make install
要sudo,不然会失败。make test
会花费一定的时间,是在跑所有的测试样例,这一步可有可无。
Install tk 8.5.0
1 | cd ./Tk8.5.0/unix |
注意:
- 一定要
--enable-shared
, 不然之后的tix无法使用它 - 如果系统中有多个tcl,也可以在
configure
的后面指定是哪个版本的tcl:--with-tcl=/path/to/tcl
- 这里的
make
如果失败,提示permission deny
,则加上sudo
。
Install tix 8.4.2
一定要下载这个版本:tix 8.4.2。这个版本是稳定的,下载地址:
http://tix.sourceforge.net/download.shtml
1 | cd ./Tix8.4.2/unix |
注意:
- 在
configure
后面的LDFLAGS
是用来指定这个X11的库的,也就是之前安装的那个xQuartz - 如果需要指定它相匹配的tcl和tk,可以在
configure
后面再加上--with-tcl=/path/to/tcl
和--with-tk=/path/to/tk
- 这里的
make
或者make install
如果失败,提示permission deny
,则加上sudo
- 如果提示语法错误,则说明该tix 与之前的tk, tcl版本不兼容
特别提示:
If you are using macOS 10.7 or later, the Apple-supplied Tcl/Tk 8.5 still has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, install and use a newer version of Python and of Tcl/Tk.
也就是说,如果是macOS 10.7以上的版本,只能用tcl\tk 8.5 以上的版本。但是如果用8.5以上的版本,则无法与tix兼容,无法正确安装。所以至此,我在本机上的艰难尝试就告一段落了。。终于决定还是止步于命令行吧。
Install IVy
Ubuntu
Get the source like this:
1 | $ git clone https://github.com/Microsoft/ivy.git |
普通用户:
Install into your local Python like this
1 | $ sudo python setup.py install |
开发者:
If you want to run from the source tree for development purposes, do this instead:
1 | $ sudo python setup.py develop |
可以指定安装路径:
If you don’t want to do a system-wide install (and you aren’t using a virtual environment) there are various ways to install in your home directory. For example:
1 | $ python setup.py install --home=~ |
See the python documentation for general instructions on installing python packages.
Run
图形界面的示例:
1 | $ cd doc/examples |
命令行的示例:
1 | cd doc/examples |
或者:
1 | cd doc/examples |
Windows notes
这个是在windows下安装的一些不同之处。因为没有试过在windows下安装,所以不确定是否有效。但还是摘录如下。
Installing on Windows can be a bit challenging, but here are a few suggestions that may get you through it.
Installing Python and Python packages
Install Python 2.7.11 in the normal way. Before installing packages, you may also need to install the Visual C++ compiler for Python.
Installing Z3
After installing Z3, you need to make sure Python can find it. You can try setting the PYTHONPATH
environment variable to point to the Z3 python
directory. It might help to make sure Z3 is installed in a directory without spaces in the name. As a last resort, you can just copy the python/z3
directory into your Python installation. If you installed Python in c:/Python27
, then copy it into:
1 | c:/Python27/lib/site-packages/z3 |
If things are installed correctly, the following should produce no errors:
1 | > python |
Installing Graphviz
Get graphviz-2.38
from graphviz.org. This site is often down, so you may have to be patient. Versions downloaded from alternative sites may be broken. Install into some directory without spaces in the name, for example c:/Graphviz
.
Using scripts
The pip
package installation utility is found in c:/Python27/Scripts
. You should put this directory in your PATH
, since the IVY command line scripts will also be installed there by default. Try installing the tarjan
and ply
packages like this:
1 | > pip install tarjan |
Installing Pygraphviz
You can try installing pygraphviz
like this:
1 | > pip install pygraphviz |
However, this is likely to fail as pip
will not find the graphviz headers and libraries. As an alternative, download the release 1.3 of pygraphviz
from here. After unpacking the sources, do this:
1 | > cd pygraphviz-pygraphviz-1.3 |
This tells explicitly where you installed the graphviz headers and libraries. If this seems to work, you can test it like this:
1 | > python |
Installing Ivy
Now you can now try to install Ivy, like this:
1 | > git clone https://github.com/Microsoft/ivy.git |
If you have put c:/Python27/Scripts
in your PATH
, you should now be able to run IVy like this:
1 | > ivy ui=cti doc/examples/client_server_example.ivy |
Mac notes
Mac上的安装如下,一定要安装XQuartz、MacPorts和Xcode。
There are two options for Mac users: using the native Aqua interface or X11. Here we will describe the X11 approach.
XQuartz
Install XQuartz.
XCode
Install Xcode.
Xcode的安装需要很长的时间
MacPorts
Install MacPorts.
Install prerequisites
这些python包用Method2中的方法安装会失败,但是用port安装就可以。但是port一定要先安装成功XCode才能使用,否则会报错。
安装成功XCode 之后,用port安装如下这些包,就可以成功。用brew
,easy_install
,pip
都无法成功(不是无法安装,而是显示安装成功,却无法正常使用)。
1 | $ sudo port install graphviz python27 py27-pip py27-pygraphviz py27-ply py27-tkinter tix git |
Install Z3
z3 这个记得安装的python版本是2.7,比较稳定
1 | $ unzip z3-4.4.1-x64-osx-10.11.zip |
Install IVy
1 | $ git clone https://github.com/Microsoft/ivy.git |
The last command is to make the ivy command-line scripts available.
运行完最后一行之后,再运行
1 | $ cd doc/examples |
虽然可以运行,但是久久不能出结果。
官网上是这么说的:
For some reason, the first time you run ivy, it takes several minutes to start.
但是经过测试,,发现几个小时都没有出结果。。不知道是什么原因。。macosx目前还是乖乖用命令行吧。。
Reference
How-to-install-tix-on-mac-os-x: https://stackoverflow.com/questions/16797444/how-to-install-tix-on-mac-os-x
tcl-tk: http://www.tcl.tk/doc/howto/compile.html
官网:http://microsoft.github.io/ivy/install.html
IDLE and tkinter with Tcl/Tk on macOS: https://www.python.org/download/mac/tcltk/